ZODB: don't like self._p_changed
Dylan Reinhardt
python at dylanreinhardt.com
Fri Jan 10 14:03:29 EST 2003
There's no way changing Python built-ins is preferable.
What you *should* do is initialize *all* your list/dict subobjects using
PersistentList and PersistentMapping. Now, every time you make a change
to self.something, you know it gets persisted. Easy enough to keep track
of, yes?
More the point, leaving the built-ins alone means that using them as local
variables won't trigger persistence. It shouldn't, after all. ZODB bloats
very quickly if you over-use persistence.
If it's the syntax you don't like, another thing you can do is define:
def save(self):
self._p_changed = 1
and then call self.save() at the end of any methods that change
subobjects. Just a bit of sugar, perhaps, but I find it far more readable
than making an assignment to a private inherited attribute.
HTH,
Dylan
At 04:58 AM 1/9/2003, you wrote:
>Max M schrieb:
>>Thomas Guettler wrote:
>>
>>>Max M schrieb:
>>
>>>>Probably not. How should an object know if a mutable subobject has been
>>>>changed?
>>>
>>>
>>>The method "append" could set the flag.
>>
>>Then you would need to use specialized objects instead of the built in
>>objects. That would shurely be more cumbersome than setting the
>>persistence flag?
>
>Yes, there a classes like PersistentList and PersistentMapping, but
>this means I need to change my code.
>
>Example:
>
>my_list=PersistentList()
>my_list.append(...)
>
>my_list=some_other_list[1:] # now my_list is no more a persistent list
>
>This means, I always need to keep in mind if a list is a peristent list
>or not. That's like setting _p_changed=1.
>
>1. Solution:
>
>One solution could be to change the meaning of [] and {}.
>Dreaming:
>
>import list_persistance
>foo=[] # foo is now a persistent list.
>
>I don't know if this is possible.
>
>
>2. Solution:
>Change the functions of list and mapping datatypes to set _p_changed if
>the content was changed. This might decrease performance for nonpersistent
>application. But since there changes need to be implemented in the python
>core, they would be in C.
>
>thomas
>
>--
>http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list