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

For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to