From 0315c18fe170b1b611b7d10b5dde2f196b89a7e0 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Tue, 22 Oct 2019 16:01:14 +0500 Subject: [PATCH] Refs #26601 -- Removed obsolete workarounds for MIDDLEWARE_CLASSES setting. --- django/contrib/admindocs/middleware.py | 6 ++---- django/contrib/auth/middleware.py | 5 ++--- django/contrib/messages/storage/session.py | 3 +-- django/middleware/csrf.py | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/django/contrib/admindocs/middleware.py b/django/contrib/admindocs/middleware.py index 5291a846c65..77d77af715f 100644 --- a/django/contrib/admindocs/middleware.py +++ b/django/contrib/admindocs/middleware.py @@ -18,10 +18,8 @@ class XViewMiddleware(MiddlewareMixin): """ assert hasattr(request, 'user'), ( "The XView middleware requires authentication middleware to be " - "installed. Edit your MIDDLEWARE%s setting to insert " - "'django.contrib.auth.middleware.AuthenticationMiddleware'." % ( - "_CLASSES" if settings.MIDDLEWARE is None else "" - ) + "installed. Edit your MIDDLEWARE setting to insert " + "'django.contrib.auth.middleware.AuthenticationMiddleware'." ) if request.method == 'HEAD' and (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or (request.user.is_active and request.user.is_staff)): diff --git a/django/contrib/auth/middleware.py b/django/contrib/auth/middleware.py index f0102c4455f..5bd176ef69f 100644 --- a/django/contrib/auth/middleware.py +++ b/django/contrib/auth/middleware.py @@ -1,4 +1,3 @@ -from django.conf import settings from django.contrib import auth from django.contrib.auth import load_backend from django.contrib.auth.backends import RemoteUserBackend @@ -17,10 +16,10 @@ class AuthenticationMiddleware(MiddlewareMixin): def process_request(self, request): assert hasattr(request, 'session'), ( "The Django authentication middleware requires session middleware " - "to be installed. Edit your MIDDLEWARE%s setting to insert " + "to be installed. Edit your MIDDLEWARE setting to insert " "'django.contrib.sessions.middleware.SessionMiddleware' before " "'django.contrib.auth.middleware.AuthenticationMiddleware'." - ) % ("_CLASSES" if settings.MIDDLEWARE is None else "") + ) request.user = SimpleLazyObject(lambda: get_user(request)) diff --git a/django/contrib/messages/storage/session.py b/django/contrib/messages/storage/session.py index 59d36d14e51..170c4940ab4 100644 --- a/django/contrib/messages/storage/session.py +++ b/django/contrib/messages/storage/session.py @@ -1,6 +1,5 @@ import json -from django.conf import settings from django.contrib.messages.storage.base import BaseStorage from django.contrib.messages.storage.cookie import ( MessageDecoder, MessageEncoder, @@ -17,7 +16,7 @@ class SessionStorage(BaseStorage): assert hasattr(request, 'session'), "The session-based temporary "\ "message storage requires session middleware to be installed, "\ "and come before the message middleware in the "\ - "MIDDLEWARE%s list." % ("_CLASSES" if settings.MIDDLEWARE is None else "") + "MIDDLEWARE list." super().__init__(request, *args, **kwargs) def _get(self, *args, **kwargs): diff --git a/django/middleware/csrf.py b/django/middleware/csrf.py index abeaaff7512..77e3f042d2b 100644 --- a/django/middleware/csrf.py +++ b/django/middleware/csrf.py @@ -163,7 +163,7 @@ class CsrfViewMiddleware(MiddlewareMixin): raise ImproperlyConfigured( 'CSRF_USE_SESSIONS is enabled, but request.session is not ' 'set. SessionMiddleware must appear before CsrfViewMiddleware ' - 'in MIDDLEWARE%s.' % ('_CLASSES' if settings.MIDDLEWARE is None else '') + 'in MIDDLEWARE.' ) else: try: