Skip to content

Commit

Permalink
fix invoke_subrequest to always invoke callbacks even when use_tweens…
Browse files Browse the repository at this point in the history
…=False
  • Loading branch information
mmerickel committed Sep 13, 2016
1 parent 5a7d974 commit bf6087b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 10 additions & 0 deletions pyramid/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
iteritems_,
)

from pyramid.events import NewResponse
from pyramid.decorator import reify
from pyramid.i18n import LocalizerRequestMixin
from pyramid.response import Response, _get_response_factory
Expand Down Expand Up @@ -332,3 +333,12 @@ def apply_request_extensions(request, extensions=None):

InstancePropertyHelper.apply_properties(
request, extensions.descriptors)

def _execute_response_callbacks(request, response):
""" Execute response callbacks and emit a NewResponse event."""
registry = request.registry
if getattr(request, 'response_callbacks', False):
request._process_response_callbacks(response)

if registry.has_listeners:
registry.notify(NewResponse(request, response))
8 changes: 8 additions & 0 deletions pyramid/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pyramid.request import Request
from pyramid.view import _call_view
from pyramid.request import apply_request_extensions
from pyramid.request import _execute_response_callbacks
from pyramid.threadlocal import manager

from pyramid.traversal import (
Expand Down Expand Up @@ -202,7 +203,14 @@ def invoke_subrequest(self, request, use_tweens=False):
extensions = self.request_extensions
if extensions is not None:
apply_request_extensions(request, extensions=extensions)

response = handle_request(request)

# bw-compat, in Pyramid < 1.8 callbacks were executed even
# when use_tweens was false
if not use_tweens:
_execute_response_callbacks(request, response)

return response

finally:
Expand Down
8 changes: 1 addition & 7 deletions pyramid/tweens.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,9 @@ def response_callbacks_tween_factory(handler, registry):
:meth:`pyramid.request.Request.add_response_callback`.
"""
notify = registry.notify
def response_callbacks_tween(request):
response = handler(request)

if getattr(request, 'response_callbacks', False):
request._process_response_callbacks(response)

registry.has_listeners and notify(NewResponse(request, response))

_execute_response_callbacks(request, response)
return response
return response_callbacks_tween

Expand Down

0 comments on commit bf6087b

Please sign in to comment.