Closed tonthon closed 11 years ago
Can you give some more background on motivation and use case?
Motivation : It fixes the issue #2. Use-case : We can't use both pyramid_layout and pyramid_debugtoolbar without having an error (as described in the ticket). Those modification allow things to work well.
Can you point me to an app that has this problem? I have used pyramid_debugtoolbar with pyramid_layout without this issue, and would like to see what is different about your case. A contrived example that just exposes your problem would be great.
Here the steps I used to reproduce the problem
mkvirtualenv test_p_layout
mkdir /tmp/test_pyramid_layout
cd /tmp/test_pyramid_layout
pip install pyramid_layout
pcreate -s starter test_p_layout
cd test_p_layout
python setup.py develop
# add pyramid_layout to the pyramid.includes entry of the development.ini file
pserve development.ini
# open the browser on 127.0.0.1:6543 I get the error.
Just tried it and got the error... I've never tried it before on a plain project.
(pltest)kemeneur:pltest blaflamme$ pserve --reload development.ini
Starting subprocess with file monitor
Starting server in PID 1332.
serving on http://0.0.0.0:6543
2013-01-29 13:49:20,030 ERROR [waitress][Dummy-2] Exception when serving /
Traceback (most recent call last):
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/waitress-0.8.2-py2.7.egg/waitress/channel.py", line 329, in service
task.service()
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/waitress-0.8.2-py2.7.egg/waitress/task.py", line 173, in service
self.execute()
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/waitress-0.8.2-py2.7.egg/waitress/task.py", line 380, in execute
app_iter = self.channel.server.application(env, start_response)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/router.py", line 251, in __call__
response = self.invoke_subrequest(request, use_tweens=True)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/router.py", line 227, in invoke_subrequest
response = handle_request(request)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 133, in toolbar_tween
body = tb.render_full(request).encode('utf-8', 'replace')
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/tbtools.py", line 240, in render_full
summary = self.render_summary(include_title=False, request=request)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/tbtools.py", line 233, in render_summary
vars, request=request)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/renderers.py", line 88, in render
return helper.render(value, None, request=request)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/renderers.py", line 555, in render
registry.notify(system_values)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/registry.py", line 74, in notify
[ _ for _ in self.subscribers(events, None) ]
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/zope.interface-4.0.3-py2.7-macosx-10.8-intel.egg/zope/interface/registry.py", line 323, in subscribers
return self.adapters.subscribers(objects, provided)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/zope.interface-4.0.3-py2.7-macosx-10.8-intel.egg/zope/interface/adapter.py", line 601, in subscribers
subscription(*objects)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/config/adapters.py", line 102, in derived_subscriber
return subscriber(arg[0])
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid_layout-0.6-py2.7.egg/pyramid_layout/config.py", line 42, in add_renderer_globals
layout = layout_manager.layout
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/decorator.py", line 39, in __get__
val = self.wrapped(inst)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid_layout-0.6-py2.7.egg/pyramid_layout/layout.py", line 41, in layout
return find_layout(self.context, self.request)
File "/Users/blaflamme/Desktop/pltest/lib/python2.7/site-packages/pyramid_layout-0.6-py2.7.egg/pyramid_layout/layout.py", line 64, in find_layout
return layout(context, request)
TypeError: 'NoneType' object is not callable
I like this patch better than my hacky solution. I encounter this problem when creating view that returns str or json, but for these I have been using an ugly workaround where I just assign the layout to those views, even though the layout isn't used. However, when I started integrating velruse into my application, I found that there were no workarounds and I had to make a hack in pyramid_layout. This is a problem with pyramid_layout and I feel that this pull request may do the trick. When I finish eating lunch, I will apply this and see if it works. I don't feel that the pyramid_layout should force every view to have a layout, as there exist views where this is unnecessary.
It's a bit hacky in my pov, but I can't figure a more convenient way to handle that case.