Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge handle-broken-context

  • Loading branch information...
commit b492322a0b4a6528dc39697eb1ceda53eb0a44d7 2 parents ba63d17 + 4f767e5
@chrisrossi chrisrossi authored
View
6 CHANGES.txt
@@ -6,6 +6,12 @@ Unreleased
- Fixed bug where class panels couldn't have args.
+- Added error handling for the case where a BeforeRender event is not preceded
+ by a ContextFound event. This can happen in the case where an error occurs
+ before a context is found and then a renderer is called by an error handler,
+ as would be the case using pyramid_debugtoolbar. In this case there will be
+ no layout_manager, since the layout manager depends on the context.
+
0.5 (2012-10-23)
----------------
View
17 pyramid_layout/config.py
@@ -31,11 +31,18 @@ def add_renderer_globals(event):
# regular request, the request will be None, so globals can't be set
if request is None:
return
- layout_manager = request.layout_manager
- layout = layout_manager.layout
- event['layout'] = layout
- event['main_template'] = layout.__template__
- event['panel'] = layout_manager.render_panel
+
+ # It is possible for add render globals to get called without a context
+ # being found. This generally happens when there is an error finding
+ # the context and then an error handler which uses a renderer is
+ # called, such as would be the case if pyramid_debugtoolbar were
+ # being used.
+ layout_manager = getattr(request, 'layout_manager', None)
+ if layout_manager:
+ layout = layout_manager.layout
+ event['layout'] = layout
+ event['main_template'] = layout.__template__
+ event['panel'] = layout_manager.render_panel
def create_layout_manager(event):
View
9 pyramid_layout/tests/test_config.py
@@ -46,6 +46,15 @@ def test_request_none(self):
add_renderer_globals(event)
self.assertEqual(len(event.keys()), 2)
+ def test_context_not_found(self):
+ from pyramid_layout.config import add_renderer_globals
+ request = testing.DummyRequest()
+ event = {
+ 'request': request,
+ }
+ add_renderer_globals(event)
+ self.assertEqual(len(event.keys()), 1)
+
class Test_create_layout_manager(unittest.TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.