[Zope3-Users] What attributes are made persistent

Peter Bengtsson mail at peterbe.com
Wed Feb 15 11:49:34 EST 2006


On 2/15/06, Paul Winkler <pw_lists at slinkp.com> wrote:
> On Wed, Feb 15, 2006 at 01:21:14PM +0000, Peter Bengtsson wrote:
> > I understand the mutation stuff and I always do it like this in zope2
> > (I'm a complete beginner in the zope3 world eager to learn):
> >
> > def updatesometing(self):
> >    #self.numbers['Peter'] = "0779 123 456"
> >    numbers = self.numbers
> >    numbers['Peter'] = "0779 123 456"
> >    self.numbers = numbers
> >
> > But in zope2 land, if I derive from Persistent it magically saves ALL
> > attributes defined in __init__ assuming that I post-write to them
> > correct as shown above.
>
> That hasn't changed in zope 3.  This is just standard ZODB behavior.
> setattr will cause a save on commit regardless of the type of
> the value.  If you read Jeff's reply again carefully, he said as much.
>
> PersistentList and PersistentDict are not new, either.
> They've been used in Zope 2 projects for ages.
>
> There are still exactly three ways to get sub-object mutations to
> persist:
>
> 1) Set the "dirty bit" by hand, e.g.:
>
>      self.alist.append(1)
>      self._p_changed = 1
>
> 2) Re-assign the attribute, e.g.:
>
>      alist = self.alist
>      alist.append(1)
>      self.alist = alist
>
> 3) Using a persistent sub-object, e.g. a PersistentList instance:
>
>      self.alist.append(1)
>


Now I get it! Sorry for being slow and thanks for explaining.

So by using PersistentList it just means that you can use:
 self.alist.append(1)
in your code. The attribute, self.alist, is still saved even without
PersistentList but it just means you have to be careful when writing
to it.

Cool!

--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope3-users mailing list