[ZODB-Dev] Help: ZODB undo problem

Shane Hathaway shane@zope.com
Tue, 18 Jun 2002 20:29:24 -0400


Mike C. Fletcher wrote:
> I would love to know:
> 
>     1) How to get the "live" objects to update to their previous state 
> when I do an undo (very much preferable, as it would save a lot of 
> re-writing)
> 
>     2) How to wrap the object in a weakref-like instance that will 
> re-access the object from the database when it is un-done, and 
> preferably only when it is undone (i.e. something that won't keep the 
> object alive outside the cache, but won't constantly be re-loading the 
> object when it's not been invalidated).
> 
>     3) Why the live objects don't automatically update (I thought this 
> was magically done by the ZODB Persistence machinery through the magic 
> of the jar and cache structures).

I'm pretty sure that the answer to all three questions is to simply call 
connection.sync() after an undo.  ZODB will ghostify the right objects. 
  Note that the connection is usually available as <zodb object>._p_jar, 
so you can call "app._p_jar.sync()".

You won't find any calls to sync() in Zope because Zope opens and closes 
a database connection on every HTTP request.  Most GUI applications, 
however, keep the connection open for a long time, so occasionally they 
have to ask ZODB to bring the objects up to date with a call to sync().

Shane