Opened 10 years ago
Closed 6 years ago
#22961 closed Bug (duplicate)
StaticFilesHandler should not run middleware on 404
Reported by: | Wil Tan | Owned by: | nobody |
---|---|---|---|
Component: | contrib.staticfiles | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Nicola | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When the staticfiles WSGI handler determines that it should handle a given path, but caught a 404 exception, it should not chain to the parent WSGIHandler, but immediately return a response.
Otherwise, we would find that middleware gets run. This may have undesired side effects. In our case, we were running a selenium test (LiveServerTestCase) and got session invalidated due to a concurrent request to login and a static file that does not exist (because this latter one went through the session middleware.)
I realise that the LiveServerTestCase code has changed in Django 1.7 (which duplicated some of the code in StaticFilesHandler as django.test.testcases.FSFilesHandler)
The proposed patch is only for the StaticFilesHandler. I would like to hear from others what they think of this "fix".
Attachments (1)
Change History (4)
by , 10 years ago
Attachment: | staticfileshandler404.diff added |
---|
comment:1 by , 10 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 7 years ago
Cc: | added |
---|
comment:3 by , 6 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I think that #29353 was a duplicate. It was recently fixed and should be in Django 2.1.
The patch makes sense to me. A test would also be required.