#18577 closed Bug (fixed)
Undocumented lazy middleware initialization
Reported by: | Owned by: | Łukasz Balcerzak | |
---|---|---|---|
Component: | Documentation | Version: | 1.3 |
Severity: | Normal | Keywords: | middleware, settings |
Cc: | mahmoud@…, kurose@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The Django docs clearly state that:
Unlike the process_* methods which get called once per request, __init__ gets called only once, when the Web server starts up.
However, I just traced a bug back to the fact that middleware is apparently initialized upon serving the first request.
To reproduce, you can simply add a non-existent middleware to your middleware classes in settings.py, and observe that the dev server starts up fine, but will barf upon serving the first request:
MIDDLEWARE_CLASSES = ( 'notreallyamiddleware', 'django.middleware.common.CommonMiddleware' )
I guess this could be chalked up to a documentation bug, but honestly, in one developer's opinion, initializing at startup would be preferable.
(This was observed on 1.3, but is probably also true of other versions.)
Attachments (1)
Change History (8)
comment:1 by , 12 years ago
Component: | Core (Other) → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 12 years ago
Owner: | changed from | to
---|
by , 12 years ago
Attachment: | middleware-init-docs-update.diff added |
---|
comment:3 by , 12 years ago
Has patch: | set |
---|
comment:4 by , 12 years ago
Status: | new → assigned |
---|
comment:5 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
There isn't really a 'startup' event at the moment. Resolving on first request makes most sense, especially for the case where you might not be serving requests at all. It doesn't make sense to initialize until you need to use it. So I'm going to mark this as docs bug.