Skip to content

Commit

Permalink
- 1.4a pyramid.scripting.prepare behaved differently than 1.3 series
Browse files Browse the repository at this point in the history
  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).
  • Loading branch information
mcdonc committed Sep 30, 2012
1 parent 7ef7fc7 commit d6fb001
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions 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)
==================

Expand Down
4 changes: 4 additions & 0 deletions pyramid/scripting.py
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion pyramid/tests/test_scripting.py
Expand Up @@ -72,7 +72,7 @@ def test_it_norequest(self):
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)
Expand All @@ -85,6 +85,17 @@ def test_it_withrequest(self):
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({})
Expand Down

0 comments on commit d6fb001

Please sign in to comment.