[ZODB-Dev] undo and zodb

Jim Fulton jim@zope.com
Tue, 03 Sep 2002 10:42:38 -0400


Neil Schemenauer wrote:
> On Tue, Sep 03, 2002 at 10:29:34AM -0400, Jim Fulton wrote:
> 
>>An application bug like:
>>
>>  ob = container[oldid]
>>  del container[oldid]
>>  get_transaction().commit()
>>  container[newid] = ob
>>  get_transaction().commit()
>>
>>Can cause lossage with FileStorage if it is sufficiently unlucky. ;)
>>
> 
> Could you explain?

If a pack occurs after the first commit, then ob will no longer
be in the database. The second transaction adds a reference to ob.
The object, ob, isn't saved again unless it was changed.
The database and storage don't check that referenced objects are in the
database, so the second commit will suceed and create a dangling reference.

It would be better if the storage *did* check so that, at least, the
second transaction would fail, revealing the bug.  Even better would be
for the error to include the missing oid and for the database to
catch the error, resave the object with the missing object id and resave
the container. This would only work if it has non-ghost data for the object
in it's cache.

Jim

-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (888) 344-4332            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org