Opened 10 years ago

Closed 7 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)

staticfileshandler404.diff (1.2 KB ) - added by Wil Tan 10 years ago.

Download all attachments as: .zip

Change History (4)

by Wil Tan, 10 years ago

Attachment: staticfileshandler404.diff added

comment:1 by Tim Graham, 10 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

The patch makes sense to me. A test would also be required.

comment:2 by Nicola, 7 years ago

Cc: Nicola added

comment:3 by Claude Paroz, 7 years ago

Resolution: duplicate
Status: newclosed

I think that #29353 was a duplicate. It was recently fixed and should be in Django 2.1.

Note: See TracTickets for help on using tickets.
Back to Top