[Checkins] SVN: zope.app.publication/branches/adamg-transient/ - Replace ZODB.POSException.ConflictError with

Adam Groszer cvs-admin at zope.org
Fri Mar 9 14:50:33 UTC 2012


Log message for revision 124533:
  - Replace ZODB.POSException.ConflictError with
    transaction.interfaces.TransientError. The latter should be a more generic
    signal to retry a transaction/request.
  - Get rid of ZODB dependency.

Changed:
  U   zope.app.publication/branches/adamg-transient/CHANGES.txt
  U   zope.app.publication/branches/adamg-transient/setup.py
  U   zope.app.publication/branches/adamg-transient/src/zope/app/publication/tests/test_zopepublication.py
  U   zope.app.publication/branches/adamg-transient/src/zope/app/publication/zopepublication.py

-=-
Modified: zope.app.publication/branches/adamg-transient/CHANGES.txt
===================================================================
--- zope.app.publication/branches/adamg-transient/CHANGES.txt	2012-03-09 14:49:08 UTC (rev 124532)
+++ zope.app.publication/branches/adamg-transient/CHANGES.txt	2012-03-09 14:50:28 UTC (rev 124533)
@@ -5,9 +5,13 @@
 3.14 (unreleased)
 -----------------
 
-- Nothing changed yet.
+- Replace ZODB.POSException.ConflictError with
+  transaction.interfaces.TransientError. The latter should be a more generic
+  signal to retry a transaction/request.
 
+- Get rid of ZODB dependency.
 
+
 3.13.2 (2011-08-04)
 -------------------
 

Modified: zope.app.publication/branches/adamg-transient/setup.py
===================================================================
--- zope.app.publication/branches/adamg-transient/setup.py	2012-03-09 14:49:08 UTC (rev 124532)
+++ zope.app.publication/branches/adamg-transient/setup.py	2012-03-09 14:50:28 UTC (rev 124533)
@@ -64,9 +64,9 @@
               'zope.security',
               'zope.securitypolicy',
               'zope.site',
-              'zope.testing']),
+              'zope.testing',
+              'ZODB3']),
     install_requires=['zope.interface',
-                      'ZODB3',
                       'zope.authentication',
                       'zope.component',
                       'zope.error',
@@ -74,6 +74,7 @@
                       'zope.location',
                       'zope.publisher>=3.12.4',
                       'zope.traversing>=3.9.0',
+                      'transaction >=1.1.0',
                       'setuptools',
                       ],
     include_package_data = True,

Modified: zope.app.publication/branches/adamg-transient/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- zope.app.publication/branches/adamg-transient/src/zope/app/publication/tests/test_zopepublication.py	2012-03-09 14:49:08 UTC (rev 124532)
+++ zope.app.publication/branches/adamg-transient/src/zope/app/publication/tests/test_zopepublication.py	2012-03-09 14:50:28 UTC (rev 124533)
@@ -172,9 +172,19 @@
             verifyClass(interface, TestPublication)
 
     def testRetryAllowed(self):
-        from ZODB.POSException import ConflictError
         from zope.publisher.interfaces import Retry
+
+        # a more generic version of ConflictError, but is the better thing
+        from transaction.interfaces import TransientError
         try:
+            raise TransientError
+        except:
+            self.assertRaises(Retry, self.publication.handleException,
+                self.object, self.request, sys.exc_info(), retry_allowed=True)
+
+        # be nice and check ZODB's ConflictError
+        from ZODB.POSException import ConflictError
+        try:
             raise ConflictError
         except:
             self.assertRaises(Retry, self.publication.handleException,
@@ -187,8 +197,20 @@
                 self.object, self.request, sys.exc_info(), retry_allowed=True)
 
     def testRetryNotAllowed(self):
+        from transaction.interfaces import TransientError
+        try:
+            raise TransientError
+        except:
+            self.publication.handleException(
+                self.object, self.request, sys.exc_info(), retry_allowed=False)
+        value = ''.join(self.request.response._result).split()
+        self.assertEqual(' '.join(value[:6]),
+                         'Traceback (most recent call last): File')
+        self.assertEqual(' '.join(value[-5:]),
+                         'in testRetryNotAllowed raise TransientError'
+                         ' TransientError')
+
         from ZODB.POSException import ConflictError
-        from zope.publisher.interfaces import Retry
         try:
             raise ConflictError
         except:
@@ -201,6 +223,7 @@
                          'in testRetryNotAllowed raise ConflictError'
                          ' ConflictError: database conflict error')
 
+        from zope.publisher.interfaces import Retry
         try:
             raise Retry(sys.exc_info())
         except:
@@ -380,6 +403,22 @@
         self.assertEqual(self.object, adapter.obj)
         self.assertEqual(self.request, adapter.request)
 
+    def testExceptionResetsResponseTransientError(self):
+        from zope.publisher.browser import TestRequest
+        request = TestRequest()
+        request.response.setHeader('Content-Type', 'application/pdf')
+        request.response.setCookie('spam', 'eggs')
+        from transaction.interfaces import TransientError
+        try:
+            raise TransientError
+        except:
+            pass
+        self.publication.handleException(
+            self.object, request, sys.exc_info(), retry_allowed=False)
+        self.assertEqual(request.response.getHeader('Content-Type'),
+                         'text/html;charset=utf-8')
+        self.assertEqual(request.response._cookies, {})
+
     def testExceptionResetsResponse(self):
         from zope.publisher.browser import TestRequest
         request = TestRequest()

Modified: zope.app.publication/branches/adamg-transient/src/zope/app/publication/zopepublication.py
===================================================================
--- zope.app.publication/branches/adamg-transient/src/zope/app/publication/zopepublication.py	2012-03-09 14:49:08 UTC (rev 124532)
+++ zope.app.publication/branches/adamg-transient/src/zope/app/publication/zopepublication.py	2012-03-09 14:50:28 UTC (rev 124533)
@@ -17,14 +17,12 @@
 import logging
 from new import instancemethod
 
-from ZODB.POSException import ConflictError
 import transaction
 
 import zope.component
 import zope.component.interfaces
 from zope.component import queryMultiAdapter
 from zope.event import notify
-from zope.security.interfaces import Unauthorized
 from zope.interface import implements, providedBy
 from zope.publisher.publish import mapply
 from zope.publisher.interfaces import IExceptionSideEffects, IHeld
@@ -300,7 +298,9 @@
             raise
 
         # Convert ConflictErrors to Retry exceptions.
-        if retry_allowed and isinstance(exc_info[1], ConflictError):
+        # where transaction.interfaces.TransientError is a more generic exception
+        if retry_allowed and isinstance(exc_info[1],
+                                        transaction.interfaces.TransientError):
             tryToLogWarning(
                 'ZopePublication',
                 'Competing writes/reads at %s: %s'



More information about the checkins mailing list