summaryrefslogtreecommitdiff
path: root/django/contrib/auth/middleware.py
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2021-03-10 14:08:37 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-03-11 08:34:28 +0100
commita2d5ea626ec6aa4eab6b018c4bce58cb27e20676 (patch)
tree0a76e91b333d863300d771c8a4486a3e753023d6 /django/contrib/auth/middleware.py
parentdc86a25a677d05703e0bb021b178e44412cea7e9 (diff)
Refs #32508 -- Raised ImproperlyConfigured instead of using "assert" in middlewares.
Diffstat (limited to 'django/contrib/auth/middleware.py')
-rw-r--r--django/contrib/auth/middleware.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/django/contrib/auth/middleware.py b/django/contrib/auth/middleware.py
index 5bd176ef69..1cd84f1cc9 100644
--- a/django/contrib/auth/middleware.py
+++ b/django/contrib/auth/middleware.py
@@ -14,12 +14,14 @@ def get_user(request):
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 setting to insert "
- "'django.contrib.sessions.middleware.SessionMiddleware' before "
- "'django.contrib.auth.middleware.AuthenticationMiddleware'."
- )
+ if not hasattr(request, 'session'):
+ raise ImproperlyConfigured(
+ "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'."
+ )
request.user = SimpleLazyObject(lambda: get_user(request))