[Zope3-Users] Disappearing dictionary. Upon restart, dictionary resets.

Dominik Huber dominik.huber at perse.ch
Mon Sep 26 03:15:48 EDT 2005


Tom Dossis wrote:

>>>> I have a content component that has a property that is a dictionary,
>>>> the keys of which are objects (content components themselves). The
>>>> values are lists of strings. I've tried implementing this a couple
>>>> different ways, but each time I restart, the dictionary comes up
>>>> empty.
>>>
>
> Hi Alan,
>
> Worked for me in a quick interactive test..
>
>
> demo.py
> =======
> from persistent import Persistent
>
> class Demo(Persistent):
>     def __init__(self):
>         self.d = {}
>
>
> >>> import transaction
> >>> from demo import Demo
> >>> from zope.app.folder import Folder
> >>>
> >>> # get the root object using debugger
> >>>
> >>> root[u'test_folder'] = f = Folder()
> >>> f[u'test_object'] = ob = Demo()
> >>> ob.d
> {}
> >>> ob.d[Demo()] = ['1','2']
> >>> ob.d[Demo()] = ['a','b']
> >>> from pprint import pprint
> >>> pprint(ob.d
> {demo.Demo object at 0x415796ec>: ['a', 'b'],
>  demo.Demo object at 0x41579f2c>: ['1', '2']}
> >>> ob._p_changed = True
> >>> transaction.commit()
> >>> Ctrl-D
>
> Connect to zope again...
>
> >>>
> >>> # get the root object using debugger
> >>> ob = root[u'test_folder'][u'test_object']
> >>> from pprint import pprint
> >>> pprint(ob.d)
> {<well3.demo.Demo object at 0x4155466c>: ['a', 'b'],
>  <well3.demo.Demo object at 0x415796ec>: ['1', '2']}
> >>>

This will only work with immutable objects such as string. Otherwise, 
you will need a persistent dict or a OOBTree or you have to set  
self._p_changed manually.

Regards,
Dominik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dominik.huber.vcf
Type: text/x-vcard
Size: 154 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20050926/1f837c64/dominik.huber.vcf


More information about the Zope3-users mailing list