Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#18577 closed Bug (fixed)

Undocumented lazy middleware initialization

Reported by: makuro@… 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.

(link to docs)

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)

middleware-init-docs-update.diff (570 bytes ) - added by Łukasz Balcerzak 12 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Luke Plant, 12 years ago

Component: Core (Other)Documentation
Triage Stage: UnreviewedAccepted

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.

comment:2 by Łukasz Balcerzak, 12 years ago

Owner: changed from nobody to Łukasz Balcerzak

by Łukasz Balcerzak, 12 years ago

comment:3 by Łukasz Balcerzak, 12 years ago

Has patch: set

comment:4 by Łukasz Balcerzak, 12 years ago

Status: newassigned

comment:5 by Claude Paroz, 12 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Tim Graham <timograham@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In [590de18add78945344de049c2d3e7021fd46ce53]:

Fixed #18577 - Clarified middleware initialization.

Thanks Lukasz Balcerzak for the patch.

comment:7 by Tim Graham <timograham@…>, 12 years ago

In [8ba78a0daf037b93194ccd1eb84614d72c7482a9]:

[1.4.X] Fixed #18577 - Clarified middleware initialization.

Thanks Lukasz Balcerzak for the patch.

Backport of 590de18add from master

Note: See TracTickets for help on using tickets.
Back to Top