[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Ensure Retry exceptions
are propogated to the publisher by
Stuart Bishop
stuart at stuartbishop.net
Thu Mar 23 22:28:59 EST 2006
Log message for revision 66142:
Ensure Retry exceptions are propogated to the publisher by
zopepublication.handleException
Changed:
U Zope3/trunk/src/zope/app/publication/tests/test_zopepublication.py
U Zope3/trunk/src/zope/app/publication/zopepublication.py
U Zope3/trunk/src/zope/publisher/interfaces/__init__.py
-=-
Modified: Zope3/trunk/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/tests/test_zopepublication.py 2006-03-23 18:58:35 UTC (rev 66141)
+++ Zope3/trunk/src/zope/app/publication/tests/test_zopepublication.py 2006-03-24 03:28:57 UTC (rev 66142)
@@ -155,18 +155,23 @@
try:
raise ConflictError
except:
- pass
- self.assertRaises(Retry, self.publication.handleException,
- self.object, self.request, sys.exc_info(), retry_allowed=True)
+ self.assertRaises(Retry, self.publication.handleException,
+ self.object, self.request, sys.exc_info(), retry_allowed=True)
+ try:
+ raise Retry(sys.exc_info())
+ except:
+ self.assertRaises(Retry, self.publication.handleException,
+ self.object, self.request, sys.exc_info(), retry_allowed=True)
+
def testRetryNotAllowed(self):
from ZODB.POSException import ConflictError
+ from zope.publisher.interfaces import Retry
try:
raise ConflictError
except:
- pass
- self.publication.handleException(
- self.object, self.request, sys.exc_info(), retry_allowed=False)
+ 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')
@@ -174,6 +179,32 @@
'in testRetryNotAllowed raise ConflictError'
' ConflictError: database conflict error')
+ try:
+ raise Retry(sys.exc_info())
+ 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[-8:]),
+ 'in testRetryNotAllowed raise Retry(sys.exc_info())'
+ ' Retry: database conflict error')
+
+ try:
+ raise Retry
+ 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[-6:]),
+ 'in testRetryNotAllowed raise Retry'
+ ' Retry: None')
+
+
+
def testViewOnException(self):
from zope.interface import Interface
class E1(Exception):
Modified: Zope3/trunk/src/zope/app/publication/zopepublication.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/zopepublication.py 2006-03-23 18:58:35 UTC (rev 66141)
+++ Zope3/trunk/src/zope/app/publication/zopepublication.py 2006-03-24 03:28:57 UTC (rev 66142)
@@ -242,6 +242,10 @@
# It must definitely be aborted.
transaction.abort()
+ # Reraise Retry exceptions for the publisher to deal with.
+ if retry_allowed and isinstance(exc_info[1], Retry):
+ raise
+
# Convert ConflictErrors to Retry exceptions.
if retry_allowed and isinstance(exc_info[1], ConflictError):
tryToLogWarning('ZopePublication',
Modified: Zope3/trunk/src/zope/publisher/interfaces/__init__.py
===================================================================
--- Zope3/trunk/src/zope/publisher/interfaces/__init__.py 2006-03-23 18:58:35 UTC (rev 66141)
+++ Zope3/trunk/src/zope/publisher/interfaces/__init__.py 2006-03-24 03:28:57 UTC (rev 66142)
@@ -139,13 +139,16 @@
implements(IRetry)
def __init__(self, orig_exc=None):
+ """orig_exc must be a 3-tuple as returned from sys.exc_info() or None"""
self.orig_exc = orig_exc
def getOriginalException(self):
return self.orig_exc
def __str__(self):
- return repr(self.orig_exc)
+ if self.orig_exc is None:
+ return 'None'
+ return str(self.orig_exc[1])
class IExceptionSideEffects(Interface):
More information about the Zope3-Checkins
mailing list