[ZODB-Dev] Dynamic Wrapper?

Tim Peters tim at zope.com
Fri Dec 16 11:13:39 EST 2005


[Chris Spencer]
> Instead of requiring all persistable objects to inherit a special class,
> wouldn't it be possible to dynamically wrap a class's __setattr__ and/or
> __setitem__ methods to determine when an object's been modified?

I'm not clear on what you're trying to accomplish, but any persistence
system needs to do a lot more than just note when an attribute has changed.
For example, it also needs ways to avoid loading the transitive closure of
all persistent state reachable from a persistent object P when P is loaded,
and to materialize reachable state as needed as attributes of P get
referenced; it needs ways to manage caches of persistent objects; it needs a
way to associate unique identifiers (object ids; oids) with persistent
objects; it needs to associate objects with the connections from which they
were loaded; etc.

.. [snipped implementation sketch, because I don't understand its goal] .. 

> I understand this has some drawbacks. Namely, it will only work for
> new-style classes, but for a large code base this might be easier than
> manually writing _p_changed = 1 everywhere.

If that's the goal, you may be alone in caring about it ;-):  manual
fiddling of _p_changed is rarely needed outside the _implementation_ of
persistence.  If you find yourself doing it a lot, there may be a flaw in
your design, or in your mental model of how persistence in ZODB actually
works.



More information about the ZODB-Dev mailing list