Undocumented lazy middleware initialization
|Reported by:||Owned by:||Łukasz Balcerzak|
|Cc:||mahmoud@…, kurose@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.)
Change History (8)
comment:1 Changed 4 years ago by
|Component:||Core (Other) → Documentation|
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|