[Zope] behavior of __setstate__ for version updates
Terry Kerr
terry@adroit.net
Sat, 13 May 2000 16:21:39 +1000
Scott,
I have been fiddling with this stuff as well lately. Basically, changes that are
made in the __setstate__ method are not committed to the DB. The only way that
changes to the object made in the __setstate__ method will 'stick' is if the
object is later modified, therefore saved, before you do the zope restart.
terry
as a Scott Parish wrote:
> I would like to use setstate to update my new product version; i can't however
> seem to figure out how to get it to work as i would like. Here is what i
> am trying.
>
> In my product, i have defined setstate as follows:
>
> def __setstate__(self, state):
> Persistent.__setstate__(self, state)
>
> if not hasattr(self, 'blah'):
> self.blah = "This is a test"
>
> I also have added:
>
> def change_blah(self):
> """ docstring """
> self.blah = "That was a test"
> return "blah changed"
>
> I restart zope, and visit a page that uses a dtml-var tag to print blah. It
> prints "This is a test" as expected. I then visit the changed_blah page,
> and go back to the dtml-var page at which point it displays "That was a test",
> also as i would have expected.
>
> Now if i restart and go back to the page, it states "This is a test". Why
> wasn't the thing stored in the ZODB? Also, if i comment out my two lines
> in __setstate__, restart, and try to access blah, it doesn't exist? Why
> isn't it getting written to the ZODB at all?
>
> After grepping about, i found that Xen does a get_transaction().commit() after
> their setstate stuff, but doing that doesn't seem to do me any good either.
>
> Am i incorrect to think that this should opperate differently then this?
>
> thanks
> sRp
>
> --
> Scott Parish
> http://srparish.net
>
> ------------------------------------------------------------------------
> Part 1.2Type: application/pgp-signature