Question regarding InvalidObjectReference and the storing of objects in the session
Hi list, I've had a system where I was storing object URLs in the session, and using restrictedTraverse to access the objects. I got it in my mind today that perhaps my knowledge of zope had expanded to the degree that I could figure out how to bypass this step and simply store the objects themselves in the session. So I've been working on that, and pretty quickly I start to get InvalidObjectReference errors (I'm pretty sure they were why I chose the more complicated method originally). So I did some searching and I think I have a better understanding now of why this occurs. The way it goes in my head is that an object in the ZODB (and possibly other sources) cannot be stored directly in the session. Unfortunately, this doesn't seem to completely describe the error, as I've found I am sometimes able to store objects from the ZODB in the session. For example, here are two lines of code, in the same file, sequentially, with the first one working, and the second one giving me the InvalidObjectReference. session['site']['current_category'] = container.site.about #references a folder session['center_panel'] = container.site.display_category #references a page template I'm 95% sure this is the area that generates the error, because I've commented out the areas where the objects are retrieved. Thanks for any ideas, Alec Munro EOA Scientific Systems Traceback follows ('ssh' is an internal thing) <!-- Traceback (innermost last): File /usr/local/Zope-2.5.1/lib/python/ZPublisher/Publish.py, line 150, in publish_module File /usr/local/Zope-2.5.1/lib/python/ZPublisher/Publish.py, line 114, in publish File /usr/local/Zope-2.5.1/lib/python/Zope/__init__.py, line 159, in zpublisher_exception_hook (Object: ssh) File /usr/local/Zope-2.5.1/lib/python/ZPublisher/Publish.py, line 102, in publish File /usr/local/Zope-2.5.1/lib/python/Zope/__init__.py, line 173, in commit File /usr/local/Zope-2.5.1/lib/python/ZODB/Transaction.py, line 234, in commit File /usr/local/Zope-2.5.1/lib/python/ZODB/Connection.py, line 346, in commit (Info: (('Products.Transience.TransientObject', 'TransientObject'), '\x00\x00\x00\x00\x00\x00\x006', '')) InvalidObjectReference: (see above) -->
Alec Munro wrote:
I've had a system where I was storing object URLs in the session, and using restrictedTraverse to access the objects. I got it in my mind today that perhaps my knowledge of zope had expanded to the degree that I could figure out how to bypass this step and simply store the objects themselves in the session.
You can't really do that. The session is in one ZODB (TemporaryStorage), while the rest of your data is in another (most likely FileStorage). ZODB won't let you store an object from one storage in another storage... So, you'll have to stick to storing paths to objects... cheers, Chris
Chris Withers wrote:
Alec Munro wrote:
I've had a system where I was storing object URLs in the session, and using restrictedTraverse to access the objects. I got it in my mind today that perhaps my knowledge of zope had expanded to the degree that I could figure out how to bypass this step and simply store the objects themselves in the session.
You can't really do that. The session is in one ZODB (TemporaryStorage), while the rest of your data is in another (most likely FileStorage). ZODB won't let you store an object from one storage in another storage...
So, you'll have to stick to storing paths to objects...
cheers,
Chris
Thanks Chris, That's pretty much how I understood it. But I'm still kind of puzzled as to why I was able to store one object but not another. Are folders stored differently? That's about the only answer I could come up with. Take care, Alec
Alec Munro wrote at 2003-7-16 16:22 -0300:
I've had a system where I was storing object URLs in the session, and using restrictedTraverse to access the objects. ... ... bypass this step and simply store the objects themselves in the session.
Zope 2.6.1 will (probably) allow you to do that *BUT* it will not work as you expect! As Chris pointed out, the session and your object live in different ZODBs (with separate object id spaces). The ZODB does not support inter-ZODB references (its references use simply the object id and they are not unique in different ZODB's). Therefore, when you store an object from one ZODB in another one, the object (and all its descendants) is copied (in Zope 2.6.1). When you copy a folder in this way, your session may get huge. Moreover, as it creates a copy, changes to one copy are not propagated to another one. Forget about this road... Dieter
participants (3)
-
Alec Munro -
Chris Withers -
Dieter Maurer