Fixed #30941 -- Reverted "Simplified AuthenticationMiddleware a bit."

This reverts commit 2f010795e6.
This commit is contained in:
Mariusz Felisiak 2019-11-13 16:33:25 +01:00 committed by Carlton Gibson
parent ca0d50f34a
commit 6e99585c19
1 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,3 @@
from functools import partial
from django.contrib import auth
from django.contrib.auth import load_backend
from django.contrib.auth.backends import RemoteUserBackend
@ -8,6 +6,12 @@ from django.utils.deprecation import MiddlewareMixin
from django.utils.functional import SimpleLazyObject
def get_user(request):
if not hasattr(request, '_cached_user'):
request._cached_user = auth.get_user(request)
return request._cached_user
class AuthenticationMiddleware(MiddlewareMixin):
def process_request(self, request):
assert hasattr(request, 'session'), (
@ -16,7 +20,7 @@ class AuthenticationMiddleware(MiddlewareMixin):
"'django.contrib.sessions.middleware.SessionMiddleware' before "
"'django.contrib.auth.middleware.AuthenticationMiddleware'."
)
request.user = SimpleLazyObject(partial(auth.get_user, request))
request.user = SimpleLazyObject(lambda: get_user(request))
class RemoteUserMiddleware(MiddlewareMixin):