From 713bc5f2785636327f4cee40d958bcff83afa9c5 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 5 Jun 2015 17:16:11 -0400 Subject: [PATCH] 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. Fixes #1643. --- pyramid/tests/test_view.py | 14 ++++++++++++++ pyramid/view.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py index ff73a93ab6..e6b9f9e7ed 100644 --- a/pyramid/tests/test_view.py +++ b/pyramid/tests/test_view.py @@ -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 diff --git a/pyramid/view.py b/pyramid/view.py index 005e811487..2867e3d6f5 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -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, @@ -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