[Zope] __setstate__ product upgrades
Dyon Balding
dyon@adroit.net
Tue, 2 May 2000 14:45:51 +1000
Hi, I am having difficulty getting product upgrades to work
via the __setstate__ method. It is mentioned in a few places
on the zope site, for example:
(from http://www.zope.org/Members/michel/HowTos/ZODB-How-To)
__setstate__() is also useful to upgrade an object from one version to another. If you add instance attributes to your
product, older versions of the instances of that product will not have the new attribute. __setstate__ can check for the
existance of new attributes, and create them with sane defaults in older versions of the instance.
I am particularly interested in the second part of this. I
have found a couple of examples of this, one in ZCatalog and
one in Xen, but can't get it to work in my product.
My code has gone through many permutations, but the general
layout is as follows:
def __setstate__(self,state):
Persistent.__setstate__(self,state)
if self._ordermanager_version < 4:
print 'ver < 4'
self._ordermanager_version = 4
get_transaction().commit()
Where the class is inherited from Persistent among other things.
The code within the if runs, however the transaction doesn't
appear to get committed. The object in memory/cache has the
new version number, but when Zope is restarted the same code
runs again and sets the version.
I haven't found any docs on how one is supposed to do this, can
anyone point me in the right direction. Especially to some code
that shows 'the right way' :).
thanks
-d
--
Adroit | Dyon Balding dyon@adroit.net
Internet | http://www.adroit.net/
Solutions | work: +613 98888522, mobile: +61 0414992604