Yes, that does work. I am trying to keep the persistence machinery in
the persistent classes themselves. Notice with the subsequent statement
def setColor(self, color):
#self._p_changed = True
the _p_changed should be set (implicitly), and then all changes fixed
with the transaction.commit() in that method--this doesn't seem to be
the case. I can uncomment the _p_changed = True line in the setColor
method and get the desired result, but I don't see why this is required,
after all, the color attribute is a Persistent class in itself. I
suppose because the Persistent class was added in the __setstate__ it
has not fully been bootstrapped at this point and needs a little help.
(the _p_changed=True is not needed when color is a bonafide attribute)
One final observation: if I instead put the self._p_changed = True
statement in the setColor method of the Color class, it doesn't produce
the desired persistency. This is somehow related to the bootstrapping
From: David Binger [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 17, 2008 1:23 PM
You need to saved the user object with the color attribute.
The __setstate__ is just giving you the unsaved one every time.
Add 'newuser._p_changed = 1' after the first
assert statement below and it will be saved along with
your change to the Color instance.
On Jan 17, 2008, at 11:21 AM, Mika, David P (GE, Research) wrote:
print 'in test2'
newuser = self.userdb[self.id]
# setstate is called subsequently
assert hasattr(newuser, 'color')
assert newuser.getColor() == 'blue'
assert newuser.getColor() == 'red'
For more information about ZODB, see the ZODB Wiki:
ZODB-Dev mailing list - ZODB-Dev@zope.org