Fixed #21790 -- Removed reliance on an assert in auth.get_user().
Thanks matklad for the report.
This commit is contained in:
parent
20f455b3d6
commit
e1c8bc8fea
|
@ -138,15 +138,17 @@ def get_user(request):
|
|||
If no user is retrieved an instance of `AnonymousUser` is returned.
|
||||
"""
|
||||
from .models import AnonymousUser
|
||||
user = None
|
||||
try:
|
||||
user_id = request.session[SESSION_KEY]
|
||||
backend_path = request.session[BACKEND_SESSION_KEY]
|
||||
assert backend_path in settings.AUTHENTICATION_BACKENDS
|
||||
backend = load_backend(backend_path)
|
||||
user = backend.get_user(user_id) or AnonymousUser()
|
||||
except (KeyError, AssertionError):
|
||||
user = AnonymousUser()
|
||||
return user
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
if backend_path in settings.AUTHENTICATION_BACKENDS:
|
||||
backend = load_backend(backend_path)
|
||||
user = backend.get_user(user_id)
|
||||
return user or AnonymousUser()
|
||||
|
||||
|
||||
def get_permission_codename(action, opts):
|
||||
|
|
Loading…
Reference in New Issue