[ZODB-Dev] Confusion about persistent dictionaries / lists

Casey Duncan cduncan@kaivo.com
Tue, 03 Jul 2001 13:27:25 -0600


Jeff Sasmor wrote:
> 
> I hope I'm not asking for a repeat of something
> already discussed on this list, I did scan thru
> a few months of the archives -- I guess I am spoiled
> by the excellent archives on NIP's system!
> 
> Anyway, I am starting a non-Zope project using
> ZODB, and having run thru the simple examples,
> have run up to something confusing (prob the
> first of many).
> 
> In several postings to this list and in various
> docs such as AMK's ZODB guide, one sees
> references to PersistentMapping and
> PersistentList.
> 
> I can see what these do, and I understand
> (I think!) why you'd use them.
> 
> What I don't get (and I am relatively new to
> Python programming outside of Zope)
> is why they aren't needed when writing
> Python classes within Zope.
> 
> For example, in one Zope product I recently
> finished (Blark weblog) I used lots of
> (ordinary) lists and dictionaries and they
> seem to go in and out of the ZODB with
> no problem even though I don't use Perisistent
> List or Mapping.
> 
> I assume that there is some magical Zope/Python
> magic going on here, but what am I missing for
> true enlightenment???
> 
> Jeff Sasmor
> jeff@sasmor.com
> www.netkook.com is an "open Zope CMF site"
> 

Actually you do. You probably just got lucky that it worked ok.
Basically the ZODB won't know to commit your change if a mutable object
(ie list or dictionary) is changed in place. With lists this would
generally mean through append or insert and with dictionaries through
assignments like dict[key]=value.

The solution is to either use the persistent classes, make a change to
the list or dictionary as a whole (by setting it to itself for instance)
or set _p_changed on the persistent parent object.
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>