[Zodb-checkins] SVN: ZODB/branches/anguenot-after_commit_hooks/src/transaction/ If an after commit hook is raising an exception then it will log a

Julien Anguenot ja at nuxeo.com
Tue Dec 20 20:31:30 EST 2005


Log message for revision 40933:
  If an after commit hook is raising an exception then it will log a
  message at error level so that if other hooks are registred they can
  be executed. We don't support execution dependencies at this level.
  
  

Changed:
  U   ZODB/branches/anguenot-after_commit_hooks/src/transaction/_transaction.py
  U   ZODB/branches/anguenot-after_commit_hooks/src/transaction/tests/test_transaction.py

-=-
Modified: ZODB/branches/anguenot-after_commit_hooks/src/transaction/_transaction.py
===================================================================
--- ZODB/branches/anguenot-after_commit_hooks/src/transaction/_transaction.py	2005-12-21 00:53:45 UTC (rev 40932)
+++ ZODB/branches/anguenot-after_commit_hooks/src/transaction/_transaction.py	2005-12-21 01:31:29 UTC (rev 40933)
@@ -405,7 +405,7 @@
             # XXX should we catch the exceptions ?
             self._callAfterCommitHooks(status=True)
         self.log.debug("commit")
-
+    
     def _saveAndGetCommitishError(self):
         self.status = Status.COMMITFAILED
         # Save the traceback for TransactionFailedError.
@@ -465,8 +465,13 @@
             # The first argument passed to the hook is a Boolean value,
             # true if the commit succeeded, or false if the commit aborted.
             args = (status,) + args
-            # XXX should we catch exceptions ? or at commit() level ?
-            hook(*args, **kws)
+            try:
+                hook(*args, **kws)
+            except:
+                # We need to catch the exceptions if we want all hooks
+                # to be called
+                self.log.error("Error in after commit hook exec in %s ",
+                               hook, exc_info=sys.exc_info())
         self._after_commit = []
         # The transaction is already committed. It must not have
         # further effects after the commit.
@@ -474,7 +479,6 @@
             # XXX is it ok for every ressource managers ?
             rm.abort(self)
         self._before_commit = []
-        # XXX do we need to cleanup some more ?
         
     def _commitResources(self):
         # Execute the two-phase commit protocol.

Modified: ZODB/branches/anguenot-after_commit_hooks/src/transaction/tests/test_transaction.py
===================================================================
--- ZODB/branches/anguenot-after_commit_hooks/src/transaction/tests/test_transaction.py	2005-12-21 00:53:45 UTC (rev 40932)
+++ ZODB/branches/anguenot-after_commit_hooks/src/transaction/tests/test_transaction.py	2005-12-21 01:31:29 UTC (rev 40933)
@@ -875,6 +875,26 @@
 
     TODO
 
+    If an after commit hook is raising an exception then it will log a
+    message at error level so that if other hooks are registred they
+    can be executed. We don't support execution dependencies at this level.
+
+      >>> mgr = transaction.TransactionManager()
+      >>> do = DataObject(mgr)
+
+      >>> def hookRaise(status, arg='no_arg', kw1='no_kw1', kw2='no_kw2'):
+      ...     raise TypeError("Fake raise")
+
+      >>> t = transaction.begin()
+
+      >>> t.addAfterCommitHook(hook, ('-', 1))
+      >>> t.addAfterCommitHook(hookRaise, ('-', 2))
+      >>> t.addAfterCommitHook(hook, ('-', 3))
+      >>> transaction.commit()
+
+      >>> log
+      ["True arg '-' kw1 1 kw2 'no_kw2'", "True arg '-' kw1 3 kw2 'no_kw2'"]
+
     """
        
 def test_suite():



More information about the Zodb-checkins mailing list