From a857ebbc65c0491f27d39c7a6c1ba485c99fee5d Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sun, 2 Apr 2017 12:48:22 -0500 Subject: add a failing test checking whether the threadlocal registry is active during config.include --- pyramid/tests/test_config/test_init.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py index 0d5413d16..53c601537 100644 --- a/pyramid/tests/test_config/test_init.py +++ b/pyramid/tests/test_config/test_init.py @@ -817,6 +817,16 @@ pyramid.tests.test_config.dummy_include2""", self.assertEqual(results['root_package'], tests) self.assertEqual(results['package'], test_config) + def test_include_threadlocals_active(self): + from pyramid.tests import test_config + from pyramid.threadlocal import get_current_registry + stack = [] + def include(config): + stack.append(get_current_registry()) + config = self._makeOne() + config.include(include) + self.assertTrue(stack[0] is config.registry) + def test_action_branching_kw_is_None(self): config = self._makeOne(autocommit=True) self.assertEqual(config.action('discrim'), None) -- cgit v1.2.3 From f5ff7e0dd3a5b8bc1fd6978e361c9ab8391b6960 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sun, 2 Apr 2017 12:50:48 -0500 Subject: push the threadlocal registry while config.include executes --- pyramid/config/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py index 304d3a85e..6c661aa59 100644 --- a/pyramid/config/__init__.py +++ b/pyramid/config/__init__.py @@ -753,6 +753,11 @@ class Configurator( .. versionadded:: 1.2 The ``route_prefix`` parameter. + .. versionchanged:: 1.9 + The included function is wrapped with a call to + :meth:`pyramid.config.Configurator.begin` and + :meth:`pyramid.config.Configurator.end` while it is executed. + """ # """ <-- emacs @@ -802,7 +807,11 @@ class Configurator( ) configurator.basepath = os.path.dirname(sourcefile) configurator.includepath = self.includepath + (spec,) - c(configurator) + self.begin() + try: + c(configurator) + finally: + self.end() def add_directive(self, name, directive, action_wrap=True): """ -- cgit v1.2.3 From bd1cce29c9d5e618c4682e7c5a37ea574aee9817 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sun, 2 Apr 2017 12:58:58 -0500 Subject: add changelog for #2989 --- CHANGES.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 7676a69f9..c8a87f625 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -18,6 +18,12 @@ Features requirement that the server is being run in this format so it may fail. See https://github.com/Pylons/pyramid/pull/2984 +- The threadlocals are now available inside any function invoked via + ``config.include``. This means the only config-time code that cannot rely + on threadlocals is code executed from non-actions inside the main. This + can be alleviated by invoking ``config.begin()`` and ``config.end()`` + appropriately. See https://github.com/Pylons/pyramid/pull/2989 + Bug Fixes --------- -- cgit v1.2.3