Need some help to get rid of an InvalidObjectReference exception

Hi zopers,

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
Traceback (most recent call last):
  File "/opt/Zope-2.7/lib/python/ZPublisher/", line 107, in publish
  File "/opt/Zope-2.7/lib/python/Zope/App/", line 222, in commit
  File "/opt/Zope-2.7/lib/python/ZODB/", line 241, in commit
    ncommitted += self._commit_objects(objects)
  File "/opt/Zope-2.7/lib/python/ZODB/", line 356, in 
    jar.commit(o, self)
  File "/opt/Zope-2.7/lib/python/ZODB/", line 452, in commit
InvalidObjectReference: Attempt to store an object from a foreign database 

after hours of googling and debugging (not very easy because traceback does not 
show the line of your product code that fired the exception), I found the line 
that is breaking everything.

    def remonterAdresses(self,p_idEntreprise=0):
        Sans arguments, cette methode retourne les adresses stockees en session.
        # XXX : attention, p_idEntreprise est totalement ignore si entreprise 
deja en session
        entreprise = self.REQUEST.SESSION.get('entreprise')
        print "GestionnaireEntreprises::remonterAdresses..."
        if not entreprise :
            entreprise = Entreprise(self,p_idEntreprise)
            print "mise de entreprise en session.."
            print "...mise en session OK"

        adresses = entreprise.remonterAdresses()
        print "GestionnaireEntreprises::remonterAdresses OK, adresses = 
        return adresses

Now, the bug comes form the line 

entreprise is an instance of Entreprise. I never put objects of this class in 
the ZODB because I don't need them to persist, they're just temporary. However, 
because Entreprises objects need to access to other objects that are in the 
ZODB, I pass them self as first argument, so that they can use it as a 
"context" to acquire other objects (for examples, Z SQL Methods). So inside 
Entreprise code, I can do something like self.context.zsql_method_something... 
because self.context is a reference to the caller, which lives in the ZODB. The 
caller is gestionnaireEntrprises.

So my question is : what is wrong with that ? Why do I get this 
InvalidObjectReference ? is it the entreprise object that is in the session ? 
is it the gestionnaireEntreprises that is stored as an attribute of the 
entreprise object ? maybe both ? 

Thank you for any advice.

Zope 2.7
python 2.3
plone 2.0.5

Zope maillist  -
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to