Undocumented lazy middleware initialization
|Reported by:||makuro@…||Owned by:||LukaszBalcerzak|
|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 3 years ago by lukeplant
- Component changed from Core (Other) to Documentation
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
Changed 3 years ago by LukaszBalcerzak
comment:6 Changed 3 years ago by Tim Graham <timograham@…>
- Resolution set to fixed
- Status changed from assigned to closed