According to the zope book it should be possible to store dicts in session. When I try to assign a dictionary to a ordinary zope 2 session, with lists there is no problem. why?: requestlist = {} for i in self.request.form: key = i value = self.request.form[i] requestlist[i] = self.request.form[i] sess = self.context.REQUEST.SESSION sess['pr_reqlist'] = requestlist I get the following error: Traceback (innermost last): * Module ZPublisher.Publish, line 196, in publish_module_standard * Module Products.PlacelessTranslationService.PatchStringIO, line 34, in new_publish * Module ZPublisher.Publish, line 146, in publish * Module Zope2.App.startup, line 222, in zpublisher_exception_hook * Module ZPublisher.Publish, line 121, in publish * Module Zope2.App.startup, line 240, in commit * Module transaction._manager, line 96, in commit * Module transaction._transaction, line 380, in commit * Module transaction._transaction, line 378, in commit * Module transaction._transaction, line 433, in _commitResources * Module ZODB.Connection, line 484, in commit * Module ZODB.Connection, line 526, in _commit * Module ZODB.Connection, line 553, in _store_objects * Module ZODB.serialize, line 407, in serialize * Module ZODB.serialize, line 416, in _dump * Module copy_reg, line 69, in _reduce_ex TypeError: can't pickle instancemethod objects (Also, the following error occurred while attempting to render the standard error message, please see the event log for full details: An operation previously failed, with traceback: File "C:\Python\Zope\Zope\lib\python\ZServer\PubCore\ZServerPublisher.py", line 23, in __init__ response=response) File "C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line 395, in publish_module environ, debug, request, response) File "C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line 196, in publish_module_standard response = publish(request, module_name, after_list, debug=debug) File "C:\Python\Zope\Instance\Products\PlacelessTranslationService\PatchStringIO.py", line 34, in new_publish x = Publish.old_publish(request, module_name, after_list, debug) File "C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line 121, in publish transactions_manager.commit() File "C:\Python\Zope\Zope\lib\python\Zope2\App\startup.py", line 240, in commit transaction.commit() File "C:\Python\Zope\Zope\lib\python\transaction\_manager.py", line 96, in commit return self.get().commit(sub, deprecation_wng=False) File "C:\Python\Zope\Zope\lib\python\transaction\_transaction.py", line 380, in commit self._saveCommitishError() # This raises! File "C:\Python\Zope\Zope\lib\python\transaction\_transaction.py", line 378, in commit self._commitResources() File "C:\Python\Zope\Zope\lib\python\transaction\_transaction.py", line 433, in _commitResources rm.commit(self) File "C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 484, in commit self._commit(transaction) File "C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 526, in _commit self._store_objects(ObjectWriter(obj), transaction) File "C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 553, in _store_objects p = writer.serialize(obj) # This calls __getstate__ of obj File "C:\Python\Zope\Zope\lib\python\ZODB\serialize.py", line 407, in serialize return self._dump(meta, obj.__getstate__()) File "C:\Python\Zope\Zope\lib\python\ZODB\serialize.py", line 416, in _dump self._p.dump(state) File "C:\Python\Zope\Python\lib\copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle instancemethod objects )
According to the zope book it should be possible to store dicts in session. When I try to assign a dictionary to a ordinary zope 2 session, with lists there is no problem. why?: (...) base.__name__ TypeError: can't pickle instancemethod objects )
Seems that you're assigning unpickable objects (instancemethod) to the session. Check what is (what types of objects) in your requestlist variable. Try to assign just {'key1':'val1'} to the session and see if this works. Yur example works for me (in Script (Python) on Zope 2.8.8). Is this exactly the code you're using? -- Maciej Wisniowski
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Maciej Wisniowski wrote:
According to the zope book it should be possible to store dicts in session. When I try to assign a dictionary to a ordinary zope 2 session, with lists there is no problem. why?: (...) base.__name__ TypeError: can't pickle instancemethod objects )
Seems that you're assigning unpickable objects (instancemethod) to the session. Check what is (what types of objects) in your requestlist variable. Try to assign just {'key1':'val1'} to the session and see if this works.
Yur example works for me (in Script (Python) on Zope 2.8.8). Is this exactly the code you're using?
Another thing: if your form includes file upload fields, you can't stash the file handle (created by 'cgi.FieldStorage') in the ZODB (and therefore, in a ZODB-backed session). Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@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 iD8DBQFFpR1i+gerLs4ltQ4RAuSzAJ4ta6vywXH8LGDoZ0L8NQWy9adsJACgv6DW B7N7OlaY+quhT9bjdoyLqR8= =JCwQ -----END PGP SIGNATURE-----
Quite possible that you have a form with something like this: <input name="user.age:record" value="50" /> <input name="user.name:record" value="Dee" /> In python, if you do this:: def saveUser(self, user, REQUEST): print user # will print {'age':'50', 'name':'Dee'} REQUEST.SESSION.set('user_data', user) # will fail! So you have to do this:: def saveUser(self, user, REQUEST): user = dict(user) print user # will print {'age':'50', 'name':'Dee'} REQUEST.SESSION.set('user_data', user) # will work! Dennis Schulz wrote:
According to the zope book it should be possible to store dicts in session. When I try to assign a dictionary to a ordinary zope 2 session, with lists there is no problem. why?:
requestlist = {} for i in self.request.form: key = i value = self.request.form[i] requestlist[i] = self.request.form[i] sess = self.context.REQUEST.SESSION sess['pr_reqlist'] = requestlist
I get the following error:
Traceback (innermost last):
* Module ZPublisher.Publish, line 196, in publish_module_standard * Module Products.PlacelessTranslationService.PatchStringIO, line 34, in new_publish * Module ZPublisher.Publish, line 146, in publish * Module Zope2.App.startup, line 222, in zpublisher_exception_hook * Module ZPublisher.Publish, line 121, in publish * Module Zope2.App.startup, line 240, in commit * Module transaction._manager, line 96, in commit * Module transaction._transaction, line 380, in commit * Module transaction._transaction, line 378, in commit * Module transaction._transaction, line 433, in _commitResources * Module ZODB.Connection, line 484, in commit * Module ZODB.Connection, line 526, in _commit * Module ZODB.Connection, line 553, in _store_objects * Module ZODB.serialize, line 407, in serialize * Module ZODB.serialize, line 416, in _dump * Module copy_reg, line 69, in _reduce_ex
TypeError: can't pickle instancemethod objects (Also, the following error occurred while attempting to render the standard error message, please see the event log for full details: An operation previously failed, with traceback: File "C:\Python\Zope\Zope\lib\python\ZServer\PubCore\ZServerPublisher.py", line 23, in __init__ response=response) File "C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line 395, in publish_module environ, debug, request, response) File "C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line 196, in publish_module_standard response = publish(request, module_name, after_list, debug=debug) File "C:\Python\Zope\Instance\Products\PlacelessTranslationService\PatchStringIO.py", line 34, in new_publish x = Publish.old_publish(request, module_name, after_list, debug) File "C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line 121, in publish transactions_manager.commit() File "C:\Python\Zope\Zope\lib\python\Zope2\App\startup.py", line 240, in commit transaction.commit() File "C:\Python\Zope\Zope\lib\python\transaction\_manager.py", line 96, in commit return self.get().commit(sub, deprecation_wng=False) File "C:\Python\Zope\Zope\lib\python\transaction\_transaction.py", line 380, in commit self._saveCommitishError() # This raises! File "C:\Python\Zope\Zope\lib\python\transaction\_transaction.py", line 378, in commit self._commitResources() File "C:\Python\Zope\Zope\lib\python\transaction\_transaction.py", line 433, in _commitResources rm.commit(self) File "C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 484, in commit self._commit(transaction) File "C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 526, in _commit self._store_objects(ObjectWriter(obj), transaction) File "C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 553, in _store_objects p = writer.serialize(obj) # This calls __getstate__ of obj File "C:\Python\Zope\Zope\lib\python\ZODB\serialize.py", line 407, in serialize return self._dump(meta, obj.__getstate__()) File "C:\Python\Zope\Zope\lib\python\ZODB\serialize.py", line 416, in _dump self._p.dump(state) File "C:\Python\Zope\Python\lib\copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle instancemethod objects )
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Peter Bengtsson wrote at 2007-1-10 20:23 +0000:
Quite possible that you have a form with something like this:
<input name="user.age:record" value="50" /> <input name="user.name:record" value="Dee" />
In python, if you do this::
def saveUser(self, user, REQUEST): print user # will print {'age':'50', 'name':'Dee'} REQUEST.SESSION.set('user_data', user) # will fail!
So you have to do this::
def saveUser(self, user, REQUEST): user = dict(user) print user # will print {'age':'50', 'name':'Dee'} REQUEST.SESSION.set('user_data', user) # will work!
"ZPublisher.HTTPRequest.record" instances (they are used for ":record" form variable) are picklable. Thus, there should be no difference when you store a "record" "r" or "dict(r)" in the session. -- Dieter
participants (5)
-
Dennis Schulz -
Dieter Maurer -
Maciej Wisniowski -
Peter Bengtsson -
Tres Seaver