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

chaouche yacine yacinechaouche at yahoo.com
Wed Aug 20 13:23:08 EDT 2008



> Whatever you are doing, you are doing the "wrong
> thing".
> 
> You are instantiating persistent objects and not storing
> them in the
> ZODB. This is going to cause your ZODB to grow, so you
> might as well
> store them.
> 
> Otherwise you need to make non-persistent versions of the
> objects you
> are trying to 'cache' and use those instead.
> 
> -- 
> Andrew Milton
> akm at theinternet.com.au

Not exactly. I am instantiating non persistent objects that do have a reference to persistence objects in the form of an attribute, and then trying to cache those non persistent objects.

Do the fact that these non persistent objects store a reference to persistent ones turn them into persistent ? I am curious to know.

Anyway, I tried the volatile attribute thing (http://wiki.zope.org/ZODB/VolatileAttributes) and first tests look fine.

This is how I did the trick :

===================
ZODBLivinObject.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 sayHi(self):
        """
        """
        # NonZODBObject stores a reference of self, a ZODB-living object.
        nonZODBish = NonZODBObject(self)
        # This line breaks everything. Comment it and every thing will be just right.
        # self.REQUEST.SESSION.set('breakish',nonZODBish)
        self.setNonZODBish(nonZODBish)
        # This can be seen in the console if runzope
        print "it's me",nonZODBish.context
        return nonZODBish.context

    def setNonZODBish(self,p_nonZODBish):
        """
        """
        setattr(self,'_v_NonZODBish',p_nonZODBish)

    def getNonZODBish(self):
        """
        """
        if not hasattr(self,"_v_NonZODBish"):
            self.setNonZODBish(None)
        return self._v_NonZODBish


And then I use the setNonZODBish et getNonZODBish methods to set and access the cached value.











      


More information about the Zope mailing list