[Checkins] SVN: ZODB/trunk/src/ Added support for the transaction retry convenience

Jim Fulton jim at zope.com
Thu May 13 07:26:56 EDT 2010


Log message for revision 112272:
  Added support for the transaction retry convenience
  (transaction-manager attempts method) introduced in the
  ``transaction`` 1.1.0 release.
  

Changed:
  U   ZODB/trunk/src/CHANGES.txt
  U   ZODB/trunk/src/ZODB/POSException.py
  U   ZODB/trunk/src/ZODB/tests/testConnection.py

-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt	2010-05-13 11:10:40 UTC (rev 112271)
+++ ZODB/trunk/src/CHANGES.txt	2010-05-13 11:26:56 UTC (rev 112272)
@@ -20,6 +20,10 @@
   made moot by the introduction of multi-version concurrency control
   several years ago.
 
+- Added support for the transaction retry convenience
+  (transaction-manager attempts method) introduced in the
+  ``transaction`` 1.1.0 release.
+
 Bugs Fixed
 ----------
 

Modified: ZODB/trunk/src/ZODB/POSException.py
===================================================================
--- ZODB/trunk/src/ZODB/POSException.py	2010-05-13 11:10:40 UTC (rev 112271)
+++ ZODB/trunk/src/ZODB/POSException.py	2010-05-13 11:26:56 UTC (rev 112272)
@@ -22,6 +22,7 @@
 # BBB: We moved the two transactions to the transaction package
 from transaction.interfaces import TransactionError, TransactionFailedError
 
+import transaction.interfaces
 
 def _fmt_undo(oid, reason):
     s = reason and (": %s" % reason) or ""
@@ -67,7 +68,7 @@
         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.
 
     This transaction should be resubmitted.
@@ -234,7 +235,7 @@
         return "BTrees conflict error at %d/%d/%d: %s" % (
             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.
 
     If an object is stored and it has a reference to another object
@@ -265,7 +266,7 @@
 class VersionCommitError(VersionError):
     """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.
 
     An attempt was made to modify an object that has been modified in an

Modified: ZODB/trunk/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testConnection.py	2010-05-13 11:10:40 UTC (rev 112271)
+++ ZODB/trunk/src/ZODB/tests/testConnection.py	2010-05-13 11:26:56 UTC (rev 112272)
@@ -380,6 +380,37 @@
         -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):
 
     # It's harder to write serious tests, because some of the critical



More information about the checkins mailing list