diff options
| author | Chris McDonough <chrism@plope.com> | 2015-06-05 17:16:11 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2015-06-05 17:16:11 -0400 |
| commit | 713bc5f2785636327f4cee40d958bcff83afa9c5 (patch) | |
| tree | 09754e3a7cbaf6c1bf85a4b54ee2ed1acaca798b | |
| parent | f3c67a4217504bc7f2862ec1616342240738efae (diff) | |
| download | pyramid-713bc5f2785636327f4cee40d958bcff83afa9c5.tar.gz pyramid-713bc5f2785636327f4cee40d958bcff83afa9c5.tar.bz2 pyramid-713bc5f2785636327f4cee40d958bcff83afa9c5.zip | |
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.
| -rw-r--r-- | pyramid/tests/test_view.py | 14 | ||||
| -rw-r--r-- | pyramid/view.py | 14 |
2 files changed, 28 insertions, 0 deletions
diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py index ff73a93ab..e6b9f9e7e 100644 --- a/pyramid/tests/test_view.py +++ b/pyramid/tests/test_view.py @@ -185,6 +185,20 @@ class RenderViewToResponseTests(BaseTest, unittest.TestCase): 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 005e81148..2867e3d6f 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 |
