summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pecan/hooks.py14
-rw-r--r--tests/test_hooks.py9
2 files changed, 20 insertions, 3 deletions
diff --git a/pecan/hooks.py b/pecan/hooks.py
index 2795f95..e8848b7 100644
--- a/pecan/hooks.py
+++ b/pecan/hooks.py
@@ -160,10 +160,18 @@ class TransactionHook(PecanHook):
self.rollback()
else:
self.commit()
+
+ #
+ # If a controller was routed to, find any
+ # after_commit actions it may have registered, and perform
+ # them.
+ #
controller = getattr(state, 'controller', None)
- actions = _cfg(controller).get('after_commit', [])
- for action in actions:
- action()
+ if controller is not None:
+ actions = _cfg(controller).get('after_commit', [])
+ for action in actions:
+ action()
+
self.clear()
class RequestViewerHook(PecanHook):
diff --git a/tests/test_hooks.py b/tests/test_hooks.py
index 5a0d069..e50d5ec 100644
--- a/tests/test_hooks.py
+++ b/tests/test_hooks.py
@@ -609,6 +609,15 @@ class TestTransactionHook(object):
assert run_hook[5] == 'action-two'
assert run_hook[6] == 'clear'
+ run_hook = []
+
+ response = app.get('/fourohfour', status=404)
+ assert response.status_int == 404
+
+ assert len(run_hook) == 2
+ assert run_hook[0] == 'start_ro'
+ assert run_hook[1] == 'clear'
+
def test_transaction_hook_with_transactional_decorator(self):
run_hook = []