On Mon, Dec 13, 2010 at 3:13 AM, Joshua Bronson <[email protected]> wrote:

> I released 
> webpy-mongodb-sessions<https://github.com/jab/webpy-mongodb-sessions/tree/v0.1>
>  recently
> (originally authored by Steven Anderson) which provides a MongoDB-backed
> store for web.py sessions. Originally, when you assigned a value to a
> session attribute, the original version of the library put the value in a
> corresponding MongoDB document as-is. This restricts the types of values you
> can store in sessions to those you can put in MongoDB documents: strings,
> floats, bools, lists, dicts, None. Try to add a value of any other type and
> you'd get an error like bson.errors.InvalidDocument: Cannot encode object:
> ...
>
> One of the modifications I made was to call web.session.Store.encode on the
> value before putting it in the document, allowing you to add any pickleable
> object to the session, which is how web.session.DiskStore and DBStore work
> for exactly this reason. The downside to this approach is the data stuffed
> in the session documents is totally opaque to the database. For instance, if
> you store an "npageviews" attribute on all your sessions, and you want to
> query the database against it, you can't because it's stuffed inside a
> pickled base64-encoded string.
>
> What is the correct design here? I suspect it'd be wrong to punt and let
> the consumer decide which tradeoff to make via a setting, but now that's
> exactly what I wish I could do for my current use case.
>


I realized if we only pickle the stuff that needs pickling, we can have our
cake and eat it too:
https://github.com/jab/webpy-mongodb-sessions/commit/67cebf0a3f66147d7e43c63c5aa0562206fcc34b

I've released this as 0.2dev to pypi:
http://pypi.python.org/pypi/webpy-mongodb-sessions/0.2dev

There's an accompanying migration in the "scripts" directory to facilitate
upgrading from 0.1.

Feedback always welcome. I'll release this as 0.2 proper soon if I don't
hear any objections before then.

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to