diff options
| author | Chris McDonough <chrism@plope.com> | 2012-09-30 18:49:29 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-09-30 18:49:29 -0400 |
| commit | d6fb00161a4d482dcfff856ce59b9dc34f78c2b1 (patch) | |
| tree | dd34ee9d70c072ccac8872ce7f3252d53bf7efaf | |
| parent | 7ef7fc7f786eb40c2b7f50065df6274b69051afc (diff) | |
| download | pyramid-d6fb00161a4d482dcfff856ce59b9dc34f78c2b1.tar.gz pyramid-d6fb00161a4d482dcfff856ce59b9dc34f78c2b1.tar.bz2 pyramid-d6fb00161a4d482dcfff856ce59b9dc34f78c2b1.zip | |
- 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).
| -rw-r--r-- | CHANGES.txt | 16 | ||||
| -rw-r--r-- | pyramid/scripting.py | 4 | ||||
| -rw-r--r-- | pyramid/tests/test_scripting.py | 13 |
3 files changed, 32 insertions, 1 deletions
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({}) |
