Commit 752bf524 authored by Jim Fulton's avatar Jim Fulton

Fixed a bug that caused assertion errors if an object was added in a

savepoint, then modified and then aborted.

Also added missing code to clear registered objects when a savepoint
was rolled back.
parent bb525b6a
......@@ -325,11 +325,19 @@ class Connection(ExportImport, object):
def abort(self, transaction):
"""Abort a transaction and forget all changes."""
if self._savepoint_storage is not None:
self._abort_savepoint()
# The order is important here. We want to abort registered
# objects before we process the cache. Otherwise, we may un-add
# objects added in savepoints. If they've been modified since
# the savepoint, then they won't have _p_oid or _p_jar after
# they've been unadded. This will make the code in _abort
# confused.
self._abort()
if self._savepoint_storage is not None:
self._abort_savepoint()
self._tpc_cleanup()
def _abort(self):
......@@ -988,6 +996,7 @@ class Connection(ExportImport, object):
def _rollback(self, state):
self._abort()
self._registered_objects = []
src = self._storage
self._cache.invalidate(src.index)
src.reset(*state)
......
......@@ -17,11 +17,26 @@ $Id$
"""
import unittest
from zope.testing import doctest
import persistent.dict, transaction
def testAddingThenModifyThenAbort():
"""
>>> import ZODB.tests.util
>>> db = ZODB.tests.util.DB()
>>> connection = db.open()
>>> root = connection.root()
>>> ob = persistent.dict.PersistentDict()
>>> root['ob'] = ob
>>> sp = transaction.savepoint()
>>> ob.x = 1
>>> transaction.abort()
"""
def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('testConnectionSavepoint.txt'),
doctest.DocTestSuite(),
))
if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment