[Zope] Need some help to get rid of an InvalidObjectReference exception

chaouche yacine yacinechaouche at yahoo.com
Wed Aug 20 07:49:15 EDT 2008


--- On Wed, 8/20/08, chaouche yacine <yacinechaouche at yahoo.com> wrote:

> From: chaouche yacine <yacinechaouche at yahoo.com>
> Subject: Re: [Zope] Need some help to get rid of an InvalidObjectReference exception
> To: "Dieter Maurer" <dieter at handshake.de>
> Cc: zope at zope.org
> Date: Wednesday, August 20, 2008, 3:22 AM
> --- On Tue, 8/19/08, Dieter Maurer
> <dieter at handshake.de> wrote:
> 
> > From: Dieter Maurer <dieter at handshake.de>
> > Subject: Re: [Zope] Need some help to get rid of an
> InvalidObjectReference exception
> > To: yacinechaouche at yahoo.com
> > Cc: zope at zope.org
> > Date: Tuesday, August 19, 2008, 11:16 AM
> > chaouche yacine wrote at 2008-8-18 09:50 -0700:
> > >Need some help to get rid of an
> InvalidObjectReference
> > exception
> > >In my zope product, when I try to put some
> specific
> > object in the session, I get this :
> > >
> > >2008-08-18T14:51:02 ERROR(200) SiteError
> >
> http://www.afdas.com:8091/noyauafdas/tests/testAdresses
> > >Traceback (most recent call last):
> > >  File
> >
> "/opt/Zope-2.7/lib/python/ZPublisher/Publish.py",
> > line 107, in publish
> > >    transactions_manager.commit()
> > >  File
> >
> "/opt/Zope-2.7/lib/python/Zope/App/startup.py",
> > line 222, in commit
> > >    get_transaction().commit()
> > >  File
> >
> "/opt/Zope-2.7/lib/python/ZODB/Transaction.py",
> > line 241, in commit
> > >    ncommitted += self._commit_objects(objects)
> > >  File
> >
> "/opt/Zope-2.7/lib/python/ZODB/Transaction.py",
> > line 356, in _commit_objects
> > >    jar.commit(o, self)
> > >  File
> >
> "/opt/Zope-2.7/lib/python/ZODB/Connection.py",
> > line 452, in commit
> > >    dump(state)
> > >InvalidObjectReference: Attempt to store an object
> from
> > a foreign database connection
> > 
> > A given persistent object can only be in one (ZODB-)
> > database, not in several
> > databases at the same time.
> > 
> > You must copy the persistent object, when you want it
> to be
> > stored
> > (also) in another (ZODB-) database.
> > 
> > You can use the "_getCopy(destination)"
> method to
> > create such
> > a copy. "_getCopy" is defined by
> > "OFS.CopySupport.CopySource" inherited
> > by most Zope objects.
> > 
> > 
> > 
> > -- 
> > Dieter
> 
> I narrowed the code to what is necessary to fire this
> exception, and here is the tarball for those who want to
> test it live
> http://yacinechaouche.googlepages.com/InvalidObjectReferenceExample.tgz
> 
> This is the directory contents :
> 
> + InvalidObjectReferenceExample 
> \_ __init__.py
> \_ NonZODBObject.py
> \_+ zmi
>   \_ ZODBLivingObjectAddForm.pt
> \_ ZODBLivingObject.py
> 
> ================
> NonZODBObject.py
> ================
> class NonZODBObject:
>     """
>     Hello, i do not live in the ZODB
>     """
> 
>     def __init__(self,p_context):
>         """
>         """
> 	# This is the evil line. 
>         self.context = p_context
> 
> ===================
> ZODBLivingObject.py
> ===================
> from OFS.SimpleItem import SimpleItem
> from NonZODBObject import NonZODBObject
> 
> 
> class ZODBLivingObject(SimpleItem) :
>     """
>     Hello, I live in the ZODB.
>     """
>     meta_type = "ZODBish"
>     def __init__(self):
>         """
>         """
>         self.id = "ZODBish"
>         self.title = "ZODBish"
> 
>     def breakEverything(self):
>         """
>         """
>         nonZODBish = NonZODBObject(self)
>         # This line breaks everything.
>        
> self.REQUEST.SESSION.set('breakish',nonZODBish)
>         # This can be seen in the console if runzope
>         print "it's me",nonZODBish.context
>         return nonZODBish.context
> 
> 
> 
> __init__.py contains the code necessary to create a ZODBish
> in the ZODB through the ZMI
> zmi contains the form that adds a ZODBish through the ZMI
> 
> As you see, I do not intentionally copy objects from one
> ZODB to another... Except maybe if the session has a
> separate storage and that this breaks everything. But then,
> I could not even use the _getCopy method because nonZODBish
> do not have a _p_jar attribute.
> 
> Any help or comment would be appreciated .


No, I got it all wrong, it is much simpler than that : I cannot put any ZODB living object into the session, be it a python script, a page template, anything... this is not product specific.

So the question is now : is there another way to put some ZODB objects in the session for future use ? because there is no reason to create the same object twice or thrice in my product so I want it to stay in the session.

Thanks.








      


More information about the Zope mailing list