Skip to content

Commit

Permalink
We explicitly pass in the interfaces provided by the request as
Browse files Browse the repository at this point in the history
request_iface to _call_view; we don't want _call_view to use
request.request_iface, because render_view_to_response and friends are
pretty much limited to finding views that are not views associated with
routes, and the only thing request.request_iface is used for is to find
route-based views.  The render_view_to_response API is (and always has
been) a stepchild API reserved for use of those who actually use
traversal.  Doing this fixes an infinite recursion bug introduced in
Pyramid 1.6a1, and causes the render_view* APIs to behave as they did in
1.5 and previous. We should probably provide some sort of different API
that would allow people to find views for routes.

Fixes #1643.
  • Loading branch information
mcdonc committed Jun 5, 2015
1 parent f3c67a4 commit 713bc5f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pyramid/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ def anotherview(context, request):
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.app_iter, ['anotherview'])

def test_call_view_with_request_iface_on_request(self):
# See https://github.com/Pylons/pyramid/issues/1643
from zope.interface import Interface
class IWontBeFound(Interface): pass
context = self._makeContext()
request = self._makeRequest()
request.request_iface = IWontBeFound
response = DummyResponse('aview')
view = make_view(response)
self._registerView(request.registry, view, 'aview')
response = self._callFUT(context, request, name='aview')
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.app_iter, ['aview'])

class RenderViewToIterableTests(BaseTest, unittest.TestCase):
def _callFUT(self, *arg, **kw):
from pyramid.view import render_view_to_iterable
Expand Down
14 changes: 14 additions & 0 deletions pyramid/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def render_view_to_response(context, request, name='', secure=True):
registry = get_current_registry()

context_iface = providedBy(context)
# We explicitly pass in the interfaces provided by the request as
# request_iface to _call_view; we don't want _call_view to use
# request.request_iface, because render_view_to_response and friends are
# pretty much limited to finding views that are not views associated with
# routes, and the only thing request.request_iface is used for is to find
# route-based views. The render_view_to_response API is (and always has
# been) a stepchild API reserved for use of those who actually use
# traversal. Doing this fixes an infinite recursion bug introduced in
# Pyramid 1.6a1, and causes the render_view* APIs to behave as they did in
# 1.5 and previous. We should probably provide some sort of different API
# that would allow people to find views for routes. See
# https://github.com/Pylons/pyramid/issues/1643 for more info.
request_iface = providedBy(request)

response = _call_view(
registry,
Expand All @@ -57,6 +70,7 @@ def render_view_to_response(context, request, name='', secure=True):
context_iface,
name,
secure=secure,
request_iface=request_iface,
)

return response # NB: might be None
Expand Down

0 comments on commit 713bc5f

Please sign in to comment.