[Zope-CMF] Re: [Zope] Persistent dictionaries
   
    Michael R. Bernstein
     
    webmaven@lvcm.com
       
    23 Aug 2001 22:08:08 -0700
    
    
  
On Thu, 2001-08-23 at 17:54, Thomas Olsen wrote:
>
> and my derived classes look something like this:
> 
> ---snip--------------------------------------------
> class TextElement(AbstractElement):
>     """
>     text element.
>     """
>     meta_type = 'Text Element'
> 
>     def __init__(self, id):
>         self.id = id
>         self._attributes = {'value':'','html':'','alignment':''}
> 
>     def edit(self, value, html, alignment):
>         """ Update the properties """
>         self._attributes['alignment'] = str(alignment)
>         self._attributes['value'] = str(value)
>         self._attributes['html'] = utils._format_stx(self.value)
> ---snip--------------------------------------------
> 
> It works great - until the object gets unloaded from the memory :-(
> 
> What am I doing wrong?
Unless I miss my guess, this is because Zope doesn't persist changes to
mutable subobjects automatically. Dictionaries (like lists) are mutable
types, so you need to inform the persistence machinery that something
has changed:
self.__changed__(1)
Immutable properties, such as strings or tuples, don't have this
requirement.
HTH,
Michael Bernstein.