Opened 14 months ago

Last modified 14 months ago

#22961 new Bug

StaticFilesHandler should not run middleware on 404

Reported by: dready Owned by: nobody
Component: contrib.staticfiles Version: 1.6
Severity: Normal Keywords:
Cc: 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 dready 14 months ago.

Download all attachments as: .zip

Change History (2)

Changed 14 months ago by dready

comment:1 Changed 14 months ago by timo

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

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