Make request exception handling more robust to subsequent exceptions
|Reported by:||Owned by:||nobody|
|Cc:||numerodix@…, django@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In django/core/handlers/base.py, there is the following piece of code:
except: # Handle everything else.
# Get the exception info now, in case another exception is thrown later.
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
Contrary to the comment, the exception info is saved too late. If, during the got_request_exception signal handling another exception occurs (and gets ignored), it will overwrite sys.exc.info(), and this subsequent exception will get logged, instead of the original one.
I hit this while playing with MySQL's SSCursor (for exporting a lot of data to CSV). Some exception happened in my application, then Django's default got_request_exception handler kicked in and attempted to rollback. This failed with a ProgrammingError, because not all rows were consumed, and this ProgrammingError went into the traceback e-mail instead of the original exception.