Commit 364b2a21 authored by Jim Fulton's avatar Jim Fulton

Added support for the transaction retry convenience

(transaction-manager attempts method) introduced in the
``transaction`` 1.1.0 release.
parent d5084e27
...@@ -20,6 +20,10 @@ New Features ...@@ -20,6 +20,10 @@ New Features
made moot by the introduction of multi-version concurrency control made moot by the introduction of multi-version concurrency control
several years ago. several years ago.
- Added support for the transaction retry convenience
(transaction-manager attempts method) introduced in the
``transaction`` 1.1.0 release.
Bugs Fixed Bugs Fixed
---------- ----------
......
...@@ -22,6 +22,7 @@ from ZODB.utils import oid_repr, readable_tid_repr ...@@ -22,6 +22,7 @@ from ZODB.utils import oid_repr, readable_tid_repr
# BBB: We moved the two transactions to the transaction package # BBB: We moved the two transactions to the transaction package
from transaction.interfaces import TransactionError, TransactionFailedError from transaction.interfaces import TransactionError, TransactionFailedError
import transaction.interfaces
def _fmt_undo(oid, reason): def _fmt_undo(oid, reason):
s = reason and (": %s" % reason) or "" s = reason and (": %s" % reason) or ""
...@@ -67,7 +68,7 @@ class POSKeyError(POSError, KeyError): ...@@ -67,7 +68,7 @@ class POSKeyError(POSError, KeyError):
return oid_repr(self.args[0]) return oid_repr(self.args[0])
class ConflictError(POSError, TransactionError): class ConflictError(POSError, transaction.interfaces.TransientError):
"""Two transactions tried to modify the same object at once. """Two transactions tried to modify the same object at once.
This transaction should be resubmitted. This transaction should be resubmitted.
...@@ -234,7 +235,7 @@ class BTreesConflictError(ConflictError): ...@@ -234,7 +235,7 @@ class BTreesConflictError(ConflictError):
return "BTrees conflict error at %d/%d/%d: %s" % ( return "BTrees conflict error at %d/%d/%d: %s" % (
self.p1, self.p2, self.p3, self.msgs[self.reason]) self.p1, self.p2, self.p3, self.msgs[self.reason])
class DanglingReferenceError(POSError, TransactionError): class DanglingReferenceError(POSError, transaction.interfaces.TransactionError):
"""An object has a persistent reference to a missing object. """An object has a persistent reference to a missing object.
If an object is stored and it has a reference to another object If an object is stored and it has a reference to another object
...@@ -265,7 +266,7 @@ class VersionError(POSError): ...@@ -265,7 +266,7 @@ class VersionError(POSError):
class VersionCommitError(VersionError): class VersionCommitError(VersionError):
"""An invalid combination of versions was used in a version commit.""" """An invalid combination of versions was used in a version commit."""
class VersionLockError(VersionError, TransactionError): class VersionLockError(VersionError, transaction.interfaces.TransactionError):
"""Modification to an object modified in an unsaved version. """Modification to an object modified in an unsaved version.
An attempt was made to modify an object that has been modified in an An attempt was made to modify an object that has been modified in an
......
...@@ -380,6 +380,37 @@ class UserMethodTests(unittest.TestCase): ...@@ -380,6 +380,37 @@ class UserMethodTests(unittest.TestCase):
-1 -1
""" """
def test_transaction_retry_convenience():
"""
Simple test to verify integration with the transaction retry
helper my verifying that we can raise ConflictError and have it
handled properly.
This is an adaptation of the convenience tests in transaction.
>>> db = ZODB.tests.util.DB()
>>> conn = db.open()
>>> dm = conn.root()
>>> ntry = 0
>>> with transaction:
... dm['ntry'] = 0
>>> import ZODB.POSException
>>> for attempt in transaction.manager.attempts():
... with attempt as t:
... t.note('test')
... print dm['ntry'], ntry
... ntry += 1
... dm['ntry'] = ntry
... if ntry % 3:
... raise ZODB.POSException.ConflictError()
0 0
0 1
0 2
"""
class InvalidationTests(unittest.TestCase): class InvalidationTests(unittest.TestCase):
# It's harder to write serious tests, because some of the critical # It's harder to write serious tests, because some of the critical
......
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