From d6fb00161a4d482dcfff856ce59b9dc34f78c2b1 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 30 Sep 2012 18:49:29 -0400 Subject: - 1.4a ``pyramid.scripting.prepare`` behaved differently than 1.3 series function of same name. In particular, if passed a request, it would not set the ``registry`` attribute of the request like 1.3 did. A symptom would be that passing a request to ``pyramid.paster.bootstrap`` (which uses the function) that did not have a ``registry`` attribute could assume that the registry would be attached to the request by Pyramid. This assumption could be made in 1.3, but not in 1.4. The assumption can now be made in 1.4 too (a registry is attached to a request passed to bootstrap or prepare). --- CHANGES.txt | 16 ++++++++++++++++ pyramid/scripting.py | 4 ++++ pyramid/tests/test_scripting.py | 13 ++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index cfdaf4216..e40401528 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,19 @@ +Next release +============ + +Bug Fixes +--------- + +- 1.4a ``pyramid.scripting.prepare`` behaved differently than 1.3 series + function of same name. In particular, if passed a request, it would not + set the ``registry`` attribute of the request like 1.3 did. A symptom + would be that passing a request to ``pyramid.paster.bootstrap`` (which uses + the function) that did not have a ``registry`` attribute could assume that + the registry would be attached to the request by Pyramid. This assumption + could be made in 1.3, but not in 1.4. The assumption can now be made in + 1.4 too (a registry is attached to a request passed to bootstrap or + prepare). + 1.4a2 (2012-09-27) ================== diff --git a/pyramid/scripting.py b/pyramid/scripting.py index 00177986f..fdb4aa430 100644 --- a/pyramid/scripting.py +++ b/pyramid/scripting.py @@ -71,6 +71,10 @@ def prepare(request=None, registry=None): 'before trying to activate it.') if request is None: request = _make_request('/', registry) + # NB: even though _make_request might have already set registry on + # request, we reset it in case someone has passed in their own + # request. + request.registry = registry threadlocals = {'registry':registry, 'request':request} threadlocal_manager.push(threadlocals) extensions = registry.queryUtility(IRequestExtensions) diff --git a/pyramid/tests/test_scripting.py b/pyramid/tests/test_scripting.py index 1ccc7af3b..a36d1ed71 100644 --- a/pyramid/tests/test_scripting.py +++ b/pyramid/tests/test_scripting.py @@ -72,7 +72,7 @@ class Test_prepare(unittest.TestCase): self.assertEqual(self.default, self.manager.get()) self.assertEqual(request.context, root) - def test_it_withrequest(self): + def test_it_withrequest_hasregistry(self): request = DummyRequest({}) registry = request.registry = self._makeRegistry() info = self._callFUT(request=request) @@ -85,6 +85,17 @@ class Test_prepare(unittest.TestCase): closer() self.assertEqual(self.default, self.manager.get()) self.assertEqual(request.context, root) + self.assertEqual(request.registry, registry) + + def test_it_withrequest_noregistry(self): + request = DummyRequest({}) + registry = self._makeRegistry() + info = self._callFUT(request=request, registry=registry) + root, closer, request = info['root'], info['closer'], info['request'] + closer() + self.assertEqual(request.context, root) + # should be set by prepare + self.assertEqual(request.registry, registry) def test_it_with_request_and_registry(self): request = DummyRequest({}) -- cgit v1.2.3