Opened 5 years ago

Closed 5 years ago

#31616 closed Cleanup/optimization (fixed)

Add hint to the E410 about AuthenticationMiddleware.

Reported by: Keryn Knight Owned by: Hasan Ramezani
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Given an empty MIDDLEWARE in your project, you try and run the admin.
The system checks framework kicks in, giving you:

(admin.E408) 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE in order to use the admin application.
(admin.E409) 'django.contrib.messages.middleware.MessageMiddleware' must be in MIDDLEWARE in order to use the admin application.
(admin.E410) 'django.contrib.sessions.middleware.SessionMiddleware' must be in MIDDLEWARE in order to use the admin application.

You add each of those middlewares to the stack, and run the application:

File "/path/to/django/contrib/auth/middleware.py", line 23, in process_request
    ) % ("_CLASSES" if settings.MIDDLEWARE is None else "")
AssertionError: The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE setting to insert 'django.contrib.sessions.middleware.SessionMiddleware' before 'django.contrib.auth.middleware.AuthenticationMiddleware'

Ignoring the fact that it should be a system check, and it's an unfortunate side-effect of spanning 2 separate contrib apps that it isn't, if the order of the errors output was updated, we'd not see this exception in this specific scenario.

Change History (3)

comment:1 by Mariusz Felisiak, 5 years ago

Easy pickings: set
Summary: Change order of admin.checks.check_dependencies so that admin.E410 comes before admin.E408Add hint to the E410 about AuthenticationMiddleware.
Triage Stage: UnreviewedAccepted
Version: 3.0master

I agree that we can do sth better here, but I'm not sure if maintaining the order of checks is feasible in a long-term. I would add a hint to the E410, e.g.

Insert 'django.contrib.sessions.middleware.SessionMiddleware' before 'django.contrib.auth.middleware.AuthenticationMiddleware'.

comment:2 by Hasan Ramezani, 5 years ago

Has patch: set
Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:3 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 18759b22:

Fixed #31616 -- Added hint about middleware ordering for SessionMiddleware admin check.

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