StaticFilesHandler should not run middleware on 404
|Reported by:||dready||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
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".