﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18925	Exception information should be localized and passed to got_request_exception signal handlers	Oliver Beattie	nobody	"It is possible, when Django is running under Gevent (ie. via Gunicorn), for traceback information for exceptions raised while processing a request to be lost. This is because Gunicorn will [https://groups.google.com/d/topic/gevent/hdCT8cddnrw/discussion throw away traceback information] (deliberately, though it doesn't necessarily sound as if this is ""by design""), if a switch to another greenlet occurs during processing an exception.

The specific case where this has happened for me (and subsequently [https://github.com/getsentry/sentry/issues/544 destroyed traceback information about errors happening in production]), is when using a patched version of psycopg2 and a signal handler (like Sentry's) which accesses the database — causing a greenlet switch. It can be replicated by using the process described in a ticket on [https://github.com/benoitc/gunicorn/issues/214 Gunicorn's tracker].

It seems the only way to solve this is for Django to localize `sys.exc_info()` before calling signal handlers (which may do who knows what with regard to greenlet switching), and to pass it explicitly to signal handlers. This shouldn't cause any issues with existing signal handlers since they all must accept `**kwargs` anyway. I've prepared a patch, which I'll submit via a Pull Request on GitHub referencing this ticket.

On my install, before applying the patch, Django error pages would appear without traceback information; after the change, they have a proper stack trace, as expected."	Bug	closed	HTTP handling	1.4	Normal	wontfix			Unreviewed	1	0	0	0	0	0
