Permalink
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 01, 2017
Commits on Jul 03, 2017
Merge pull request #65 from mmerickel/commit-veto-overrides-squashed-…
…exception

allow the commit_veto to handle squashed exceptions
Showing with 28 additions and 10 deletions.
  1. +10 −10 pyramid_tm/__init__.py
  2. +18 −0 pyramid_tm/tests.py
View
@@ -137,18 +137,18 @@ def tm_tween(request):
if manager.isDoomed():
raise AbortWithResponse(response)
# check for a squashed exception and handle it
# this would happen if an exception view was invoked and
# rendered an error response
exc_info = getattr(request, 'exc_info', None)
if exc_info is not None:
maybe_tag_retryable(request, exc_info)
raise AbortWithResponse(response)
if commit_veto is not None:
veto = commit_veto(request, response)
if veto:
if commit_veto(request, response):
raise AbortWithResponse(response)
else:
# check for a squashed exception and handle it
# this would happen if an exception view was invoked and
# rendered an error response
exc_info = getattr(request, 'exc_info', None)
if exc_info is not None:
maybe_tag_retryable(request, exc_info)
raise AbortWithResponse(response)
return _finish(request, manager.commit, response)
except AbortWithResponse as e:
View
@@ -502,6 +502,24 @@ def exc_view(request):
self.assertEqual(resp.body, b'failure')
self.assertEqual(dm.action, 'abort')
def test_handled_error_commits_with_veto(self):
config = self.config
dm = DummyDataManager()
def view(request):
dm.bind(request.tm)
raise ValueError
config.add_view(view)
def exc_view(request):
return 'failure'
def commit_veto(request, response):
return request.exception is None
config.add_settings({'tm.commit_veto': commit_veto})
config.add_view(exc_view, context=ValueError, renderer='string')
app = self._makeApp()
resp = app.get('/')
self.assertEqual(resp.body, b'failure')
self.assertEqual(dm.action, 'commit')
def test_explicit_manager_fails_before_tm(self):
from transaction.interfaces import NoTransaction
config = self.config

No commit comments for this range