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

chaouche yacine yacinechaouche at yahoo.com
Mon Aug 18 12:50:08 EDT 2008


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 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

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.."
            self.REQUEST.SESSION.set('entreprise',entreprise)
            print "...mise en session OK"

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

Now, the bug comes form the line self.REQUEST.SESSION.set('entreprise',entreprise)

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




      


More information about the Zope mailing list