[ZODB-Dev] Class Versioning
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 ___ 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
Re: [ZODB-Dev] Class Versioning?
Hello Chris Spencer, Saturday, October 29, 2005, 7:16:43 AM, you wrote: CS Would it be possible to support some system of class versioning in ZODB, CS to aid to handling modifications to source code? For instance, suppose CS each class definition has a __version__ attribute. Upon serialization, CS this version is saved for each instance. Then, if the class is updated, CS signified by incrementing the class's __version__, ZODB could take CS action, for example, by executing an optional __upgrade_to_x(self) in CS the new class definition. you can easily derive your own class from Persistent class, and add some system of class versioning to them. for example ( untested ) class Persistent(_Persistent): # attributes for version tag support _class_version = None _class_tag = None _version_tag = None def __class_init__(self): # works only for extension classes tags = [ self._class_version ] for base in self.__bases__: if hasattr( base, '_class_tag' ): tags.append( base._class_tag ) self._class_tag = hash( tuple(tags) ) def __setstate__( self, state ): _Persistent.__setstate__( self, state ) if self.tagChanged(): self.doSomething() def doSomething(self): self._version_tag = self._class_tag def tagChanged(self): return self._version_tag self._class_tag class A(Persistent): _class_version = 1.3 class B(A): _class_version = 1.45 -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru ___ 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
Re: [ZODB-Dev] Class Versioning?
Lennart Regebro wrote: On 10/29/05, Chris Spencer [EMAIL PROTECTED] wrote: Would it be possible to support some system of class versioning in ZODB, to aid to handling modifications to source code? For instance, suppose each class definition has a __version__ attribute. Upon serialization, this version is saved for each instance. Then, if the class is updated, signified by incrementing the class's __version__, ZODB could take action, for example, by executing an optional __upgrade_to_x(self) in the new class definition. I don't see what benefits that would bring. It's quite easy to implement something like this on an application level. Also this doesn't allow for upgrades where you need to replace the object, which are not uncommon, so it's still not a complete solution. Agreed. For an example of such an application-level solution, see: http://svn.zope.org/Zope3/trunk/src/zope/app/generations/README.txt?view=markup Note that even though this package is in zope.app, the solution is quite general and should be usable outside of Zope. (This package really should be lifted up a level.) Jim -- Jim Fulton mailto:[EMAIL PROTECTED] Python Powered! CTO (540) 361-1714http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org ___ 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