Opened 8 years ago
Closed 7 years ago
#27796 closed Bug (fixed)
Middlewares load twice due to StaticFilesHandler(WSGIHandler)
Reported by: | Anthony King | Owned by: | Chandrakant Kumar |
---|---|---|---|
Component: | contrib.staticfiles | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In Django 1.10, a new middleware system was implemented. As part of this implementation, loading of middleware was moved to WSGIHandler.init.
When django.contrib.staticfiles
is used, StaticFilesHandler
is used as part of runserver
, which causes WSGIHandler.__init__
to be called twice.
This, in turn, causes the middlewares to all be initialised twice.
This will affect the majority of development environments. It should not affect production environments, as people should not be using runserver
.
With the example middleware, you can see the class being initialised twice.
# middleware.py class ExampleMiddleware(MiddlewareMixin): def __init__(self, get_response=None): super().__init__(get_response=get_response) print("simple_middleware - class: ", time.time(), self)
Change History (8)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
I've always thought it a bit strange that StaticFilesHandler
inherits WSGIHandler
; it seems prone to unintended effects like this one. IMO the right fix here is to make StaticFilesHandler
self-contained, even if that requires a bit more verbose WSGI-handling code in it.
comment:3 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 7 years ago
Are you still working on this Chandrakant Kumar? If not I may give it a crack.
comment:6 by , 7 years ago
Has patch: | set |
---|
I was not sure about inheritance drop and as the fix was rather straightforward, I'm still proposing a PR which keeps WSGIHandler
inheritance.
comment:7 by , 7 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
introduced in https://github.com/django/django/commit/99bb7fcc1859615a7b8c2468e7b97d54853bfb10