[Zope-dev] Help: __getstate__ overriding
Dieter Maurer
dieter at handshake.de
Fri May 28 15:00:02 EDT 2004
Syver Enstad wrote at 2004-5-28 12:41 +0200:
>I have a Persistent derived class where I want to upgrade from using a
>PersistentList to a BTrees.IOBTree.IOBTree.
>
>_articleList is the old Persistent list
>_oidsToArticles is the new IOBTree.
>
> def __setstate__(self, state):
> articleList = state.get('_articleList')
> if articleList:
> oidsToArticles = self.makeBTree()
> for each in articleList:
> oidsToArticles[each.oid()] = each
> del state['_articleList']
> state['_oidsToArticles'] = oidsToArticles
> Persistent.__setstate__(self, state)
>
>This seems to work fine, and I am adding more objects to
>_oidsToArticles. The problem is that when I commit the transaction,
>nothing is saved. I have tested the same code without __setstate__ and
>then it saves just fine. What hoops does one have to jump through to
>upgrade the state of a ZODB object?
This does not work as changes made in "__setstate__" are not
explicitly persisted. Whether or not they become persistent
depends on whether the object is changed again outside "__setstate__".
Use an explicit conversion script instead...
--
Dieter
More information about the Zope-Dev
mailing list