Hi,
I'm not sure if this is a bug or intentional behaviour, but I've had
trouble accessing exception information in response and finished callbacks.
Here is my test script (based on the hello world example from the docs):
#----
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def error(request):
raise Exception('this is an error message')
def response_callback(request, response):
print 'response', request.path_qs, response.status_int
def finished_callback(request):
print 'finished', request.path_qs, request.exception,
request.response.status_int
def on_new_request(event):
request = event.request
request.add_response_callback(response_callback)
request.add_finished_callback(finished_callback)
if __name__ == '__main__':
config = Configurator()
config.add_route('error', '/error')
config.add_view(error, route_name='error')
config.add_subscriber(on_new_request,
'pyramid.events.NewRequest')
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()
#----
With Pyramid 1.1, If I visit the /error URL I see (amongst other output):
finished /error this is an error message 200
but with Pyramid 1.3a7, I see:
finished /error None 200
It looks like the exception view tween deliberately sets the
request.exception attribute to None. Does this mean that the documentation
for response and finished callbacks should be updated to not refer to that
attribute?
(eg.
http://readthedocs.org/docs/pyramid/en/1.3-branch/narr/hooks.html#using-response-callbacks
)
Also, is there any other way of detecting whether a view raised an
exception in one of these callbacks?
Thanks a lot,
Simon
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pylons-discuss/-/w2QZKlo6JvEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.