Commit 7510464b authored by Jim Fulton's avatar Jim Fulton

Fixed a bug in commits with savepoints and changes since savepoints.

Once we start using savepoints, we need to make sure that all data are
committed through the savepoints. Otherwise, things can get committed
in the wrong order, leading to conflicts.
parent 752bf524
...@@ -63,7 +63,6 @@ class Connection(ExportImport, object): ...@@ -63,7 +63,6 @@ class Connection(ExportImport, object):
_storage = _normal_storage = _savepoint_storage = None _storage = _normal_storage = _savepoint_storage = None
_tmp = None
_code_timestamp = 0 _code_timestamp = 0
########################################################################## ##########################################################################
...@@ -437,9 +436,17 @@ class Connection(ExportImport, object): ...@@ -437,9 +436,17 @@ class Connection(ExportImport, object):
"""Commit changes to an object""" """Commit changes to an object"""
if self._savepoint_storage is not None: if self._savepoint_storage is not None:
# We first checkpoint the current changes to the savepoint
self.savepoint()
# then commit all of the savepoint changes at once
self._commit_savepoint(transaction) self._commit_savepoint(transaction)
self._commit(transaction) # No need to call _commit since savepoint did.
else:
self._commit(transaction)
def _commit(self, transaction): def _commit(self, transaction):
"""Commit changes to an object""" """Commit changes to an object"""
......
...@@ -33,6 +33,21 @@ def testAddingThenModifyThenAbort(): ...@@ -33,6 +33,21 @@ def testAddingThenModifyThenAbort():
>>> transaction.abort() >>> transaction.abort()
""" """
def testModifyThenSavePointThenModifySomeMoreThenCommit():
"""
>>> import ZODB.tests.util
>>> db = ZODB.tests.util.DB()
>>> connection = db.open()
>>> root = connection.root()
>>> sp = transaction.savepoint()
>>> root['a'] = 1
>>> sp = transaction.savepoint()
>>> root['a'] = 2
>>> transaction.commit()
"""
def test_suite(): def test_suite():
return unittest.TestSuite(( return unittest.TestSuite((
doctest.DocFileSuite('testConnectionSavepoint.txt'), doctest.DocFileSuite('testConnectionSavepoint.txt'),
......
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