On 7/14/06, Chris S <[EMAIL PROTECTED]> wrote:
I'm trying to detect a disparity between an instance __version__ and a
class __version__, signifying a class upgrade. However, I'm not sure
why the following code doesn't work.

class Foo(Persistent):
    __version__ = 1.0

    def __setstate__(self, state):
        Persistent.__setstate__( self, state )
        print self.__version__, type(self).__version__
        if self.__version__ != type(self).__version__:
            print 'upgrading'
        self.__version__ = type(self).__version__

If I persist an instance of foo, close the db, change the class
version, open my db then reload my instance, the version numbers are
always equal and it never detects an upgrade. Why isn't ZODB saving
the instance's __version__ attribute? Shouldn't the last line save
__version__ in the instance's __dict__, which should then be different
from the __class__.__version__?

Chris

Nevermind, I just realized I have to do self.__version__ =
self.__version__ at the beginning of __setstate__ or else the instance
never stores a local __version__, causing __class__.__version__ to be
used instead.

Chris
_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to