[ZODB-Dev] Adopting ZODB

Paul Winkler pw_lists at slinkp.com
Thu Jul 13 16:24:24 EDT 2006


On Thu, Jul 13, 2006 at 03:55:53PM -0400, Chris S wrote:
> not yet defined. And of course I'm not assigning to any other
> Persistent instances, since the point of the code was to show that
> Zope can't persist objects that don't inherit the Persistent class.

It can, but:

- non-Persistent objects have to be stored as attributes of
  Persistent objects.

- Modifying a mutable non-Persistent object means you have
  to either set _p_changed on the parent Persistent object,
  or re-assign the mutable to parent object.

- setting _p_changed on non-Persistent objects has no effect.

In your example, since root is the only thing Persistent,
the lines:

parent._p_changed = 1
parent.children._p_changed = 1

... have no effect.  You could instead do either of
(untested but I think these should both work):

root._p_changed = 1

...or:

setattr(root, parentName, parent)

But you don't want big chains of non-Persistent objects, it leads to
write conflict errors and unnecessary storage bloat.  Make some
Persistent wrapper classes and use them.  Use BTrees when you need a
large number of highly mutable sub-objects.

-- 

Paul Winkler
http://www.slinkp.com


More information about the ZODB-Dev mailing list