[Zope] behavior of __setstate__ for version updates

Scott Parish sRp@srparish.net
Sat, 13 May 2000 02:30:19 +0000


--/2994txjAzEdQwm5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

I would like to use setstate to update my new product version; i can't howe=
ver
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'):=20
        self.blah =3D "This is a test"=20

I also have added:

def change_blah(self):
    """ docstring """
    self.blah =3D "That was a test"=20
    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 tes=
t",
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() af=
ter
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


--=20
Scott Parish
http://srparish.net

--/2994txjAzEdQwm5
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.0 (OpenBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE5HL4sQIKxCnswXL0RASJnAJ9cciKBixUeBqtcoZ6iK8cfZPzWCgCghRnR
LTUyayYa8InGdPHy+I9ZL+M=
=A/pv
-----END PGP SIGNATURE-----

--/2994txjAzEdQwm5--