Commit abf2ac13 authored by Vincent Pelletier's avatar Vincent Pelletier

ERP5Type/patches/WSGIPublisher: Ensure transaction abort.

Transaction must be aborted even if the state is getting so bad that the
exception is being re-raised. Leaving an open-ended transaction is never
acceptable.
parent 18b5e4ed
...@@ -280,53 +280,54 @@ def transaction_pubevents(request, response, err_hook, tm=transaction.manager): ...@@ -280,53 +280,54 @@ def transaction_pubevents(request, response, err_hook, tm=transaction.manager):
exc_info = (exc_type, exc, sys.exc_info()[2]) exc_info = (exc_type, exc, sys.exc_info()[2])
try: try:
# Raise exception from app if handle-errors is False try:
# (set by zope.testbrowser in some cases) # Raise exception from app if handle-errors is False
if request.environ.get('x-wsgiorg.throw_errors', False): # (set by zope.testbrowser in some cases)
reraise(*exc_info) if request.environ.get('x-wsgiorg.throw_errors', False):
reraise(*exc_info)
if err_hook:
parents = request.get('PARENTS') if err_hook:
if parents: parents = request.get('PARENTS')
parents = parents[0] if parents:
retry = False parents = parents[0]
try: retry = False
try: try:
r = err_hook(parents, request, *exc_info) try:
assert r is response r = err_hook(parents, request, *exc_info)
exc_view_created = True
except Retry:
if request.supports_retry():
retry = True
else:
r = err_hook(parents, request, *sys.exc_info())
assert r is response assert r is response
exc_view_created = True exc_view_created = True
except (Redirect, Unauthorized): except Retry:
response.exception() if request.supports_retry():
exc_view_created = True retry = True
except BaseException as e: else:
if e is not exc: r = err_hook(parents, request, *sys.exc_info())
raise assert r is response
exc_view_created = False exc_view_created = True
else: except (Redirect, Unauthorized):
# Handle exception view response.exception()
exc_view_created = _exc_view_created_response( exc_view_created = True
exc, request, response) except BaseException as e:
if e is not exc:
if isinstance(exc, Unauthorized): raise
# _unauthorized modifies the response in-place. If this hook exc_view_created = False
# is used, an exception view for Unauthorized has to merge else:
# the state of the response and the exception instance. # Handle exception view
exc.setRealm(response.realm) exc_view_created = _exc_view_created_response(
response._unauthorized() exc, request, response)
response.setStatus(exc.getStatus())
if isinstance(exc, Unauthorized):
retry = isinstance(exc, TransientError) and request.supports_retry() # _unauthorized modifies the response in-place. If this hook
# is used, an exception view for Unauthorized has to merge
notify(pubevents.PubBeforeAbort(request, exc_info, retry)) # the state of the response and the exception instance.
tm.abort() exc.setRealm(response.realm)
notify(pubevents.PubFailure(request, exc_info, retry)) response._unauthorized()
response.setStatus(exc.getStatus())
retry = isinstance(exc, TransientError) and request.supports_retry()
finally:
notify(pubevents.PubBeforeAbort(request, exc_info, retry))
tm.abort()
notify(pubevents.PubFailure(request, exc_info, retry))
if retry: if retry:
reraise(*exc_info) reraise(*exc_info)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment