[Zope] Session and objects

Jens Vagelpohl jens@zope.com
Mon, 30 Sep 2002 07:44:17 -0400


you cannot directly store a zope object that is already stored in the 
normal ZODB. the sessioning "storage" is considered a different 
database by zope and you cannot store an object in more than one zope 
database.

what you can do is "clone" the object you are trying to store and then 
store it in the session. you must make sure whatever you are storing in 
the session has no references in the "real" ZODB.

i'm not sure what you are trying to achieve here. it is always the 
easiest to store nothing but simple python data types (strings, 
sequences, dictionaries) in a session data container. a much better 
solution might be to store something that acts as a "key" and lets you 
find what you need in the real ZODB when you need it.

jens


On Monday, Sep 30, 2002, at 06:43 US/Eastern, Bo M. Maryniuck wrote:

> Hello, all.
>
> I would like to handle session events. For example: user closes 
> browser, etc.
> Seems that is not possible, so I desire do it via the Session. But... 
> is it possible
> to add somethin non-string'ish into the SESSION? For example, I would 
> like add
> the an DB connecton or DB cursor or any other object.
> But Zope tells me something like:
>
> Error Type: InvalidObjectReference
> Error Value: Attempt to store an object from a foreign database 
> connection
>
> Traceback (innermost last):
>   File /opt/zope/lib/python/ZPublisher/Publish.py, line 150, in 
> publish_module
>   File /opt/zope/lib/python/ZPublisher/Publish.py, line 114, in publish
>   File /opt/zope/lib/python/Zope/__init__.py, line 159, in 
> zpublisher_exception_hook
>     (Object: storedProcedure)
>   File /opt/zope/lib/python/ZPublisher/Publish.py, line 102, in publish
>   File /opt/zope/lib/python/Zope/__init__.py, line 173, in commit
>   File /opt/zope/lib/python/ZODB/Transaction.py, line 234, in commit
>   File /opt/zope/lib/python/ZODB/Connection.py, line 346, in commit
>     (Info: (('Products.Transience.TransientObject', 
> 'TransientObject'), '\x00\x00\x00\x00\x00\x00\x00\x0b', ''))
> InvalidObjectReference: (see above)
>
> Is here some workaround or advantage?
>
> -- 
> Regards, Bogdan
>
> BASIC:
>         A programming language.  Related to certain social diseases
>         in that those who have it will not admit it in polite company.
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )