[Zope] Re: losing random session data
Tres Seaver
tseaver at palladion.com
Mon Mar 19 01:23:20 EDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Maciej Wisniowski wrote:
>> my data ends up looking like this:
>>
>> order [{}, {}, {'foo': '1', 'bar': 'a'}, {}, {'foo': '2', 'bar': 'b'},
>> {'foo': '6', 'bar': 'z'}, {'foo': '1', 'bar': 'a'}]
> What is wrong here? I mean what output is expected?
>
>> I've seen http://mail.zope.org/pipermail/zope-dev/2006-July/027890.html
>> and am aware that related bug existed prior to 2.7.1.
> There is 'faster' that is alternative sessioning machinery but I don't know
> if it works with 2.7
It depends on Five / Zope3: I haven't used the appropriate versions
(Five 1.0.x, ZopeX3 3.0.x) with it, and don't know whether the faster
product is compatible with them.
>> I've used sessions without problems before, this is the first time I
>> attempt to store variables in containers. What am I doing wrong?
> Maybe it is because of req.form assignment. Try to create copy of
> its values and append this to 'order' list like:
>
> session = context.REQUEST.SESSION
> order = session.get('order', [])
> order.append({'foo':req.form['foo'],
> 'bar':req.form['bar']})
> session.set('order',order)
>
> and see what happens now.
Note as well that using "mutable" Python primitives (dicts, lists) is
tricky, as they don't notify *their* container (the persistent
SessionDataObject) when they are mutatated. If you are using them,
rather than some persistent variant, then you need to rebind them into
the container. E.g.:
mapping = SESSION.get('mapping')
if mapping is None:
mapping = {}
mapping['foo'] = REQUEST.form('foo')
SESSION['mapping'] = mapping # triggers persistence
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF/h5I+gerLs4ltQ4RAk/VAJ9aBGGAMygmxkWtqQnG6tg6lJUzxgCgmtFh
KxFeFo8D77JkP9s/V++qzhk=
=HDWu
-----END PGP SIGNATURE-----
More information about the Zope
mailing list