[ZODB-Dev] question

Christian Reis kiko at async.com.br
Thu Sep 11 11:51:41 EDT 2003


On Thu, Sep 11, 2003 at 09:43:51AM -0400, Shane Hathaway wrote:
> Christian Reis wrote:
> >Well, that's half the equation. How do I update the "real" object
> >with changes done to its clone, one I've decided to commit() the
> >changes?  The situation I have is that N different objects may refer
> >to the cloned object, and I need to update the "real" one, not the
> >clone.
> >
> >Apart from updating __dict__ recursively down the subtree, is there a
> >good way to do this?
> 
> No, there is not a good way, although updating the __dict__ of only 
> the first object would be enough.  That is to say, the following 
> would work in most cases:
> 
> def updateObj(old, new):
>     old._p_changed = 1
>     old.__dict__.clear()
>     old.__dict__.update(new.__dict__)

I'm wondering why updating the first object would be enough. If we have
a situation such as:

    - many refer to A
    - many refer to B
    - A refers to B

and our code copies the A "subtree", won't we need to update both 
A_copy -> A and B_copy -> B? Otherwise, I reckon we end up with two B's
being referred to in the database (B_copy by A, and the original B by
its original referrers).

Ah, that's what "most cases" up there meant? :-)

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL



More information about the ZODB-Dev mailing list