Opened 13 years ago
Closed 12 years ago
#16367 closed New feature (wontfix)
Exceptions thrown by middleware.process_response don't get to middleware.process_exception
Reported by: | bob84123 | Owned by: | Aymeric Augustin |
---|---|---|---|
Component: | Core (Other) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I have a custom exception handler, implemented as a middleware class with a process_exception method, this handler does not receive an exception that is thrown during another middleware's process_response method. This mainly happens with django.middleware.transaction.TransactionMiddleware; if a view executes a query that violates a PostgreSQL constraint, an exception isn't thrown until the transaction is committed, which is inside the middleware, and so my exception logger can't catch that.
I have a patch that fixes the issue and doesn't break anything else (according to the test suite). I can't see any downsides of applying this, but I may be missing something, so let me know.
Attachments (1)
Change History (5)
by , 13 years ago
Attachment: | response_middleware_exception_fix.diff added |
---|
comment:1 by , 13 years ago
Component: | HTTP handling → Core (Other) |
---|---|
Needs documentation: | set |
Needs tests: | set |
Triage Stage: | Unreviewed → Design decision needed |
Type: | Bug → New feature |
comment:2 by , 13 years ago
It would to be great to have process_exception called for exceptions that happen in a middleware. Hope there is progress on this bug soon.
comment:3 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 12 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Overall, the design of Django's middleware assumes that middleware is reliable and will not throw exceptions under normal circumstances.
Besides, the current behavior is documented.
Since TransactionMiddleware is now deprecated (it's basically impossible to implement this feature reliable as a middleware), the original use case has disappeared, and I'm going to close this ticket.
Exception middleware currently works as advertised.
https://docs.djangoproject.com/en/dev/topics/http/middleware/#process-exception:
You're proposing to change its behavior, so that it will also be called if an exception happens in a middleware.
This requires a decision by a core developer.