[Zope-dev] Help: __getstate__ overriding

Syver Enstad syver at inout.no
Fri May 28 06:41:30 EDT 2004


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?





More information about the Zope-Dev mailing list