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.
|
If no user is retrieved an instance of `AnonymousUser` is returned.
|
||||||
"""
|
"""
|
||||||
from .models import AnonymousUser
|
from .models import AnonymousUser
|
||||||
|
user = None
|
||||||
try:
|
try:
|
||||||
user_id = request.session[SESSION_KEY]
|
user_id = request.session[SESSION_KEY]
|
||||||
backend_path = request.session[BACKEND_SESSION_KEY]
|
backend_path = request.session[BACKEND_SESSION_KEY]
|
||||||
assert backend_path in settings.AUTHENTICATION_BACKENDS
|
except KeyError:
|
||||||
backend = load_backend(backend_path)
|
pass
|
||||||
user = backend.get_user(user_id) or AnonymousUser()
|
else:
|
||||||
except (KeyError, AssertionError):
|
if backend_path in settings.AUTHENTICATION_BACKENDS:
|
||||||
user = AnonymousUser()
|
backend = load_backend(backend_path)
|
||||||
return user
|
user = backend.get_user(user_id)
|
||||||
|
return user or AnonymousUser()
|
||||||
|
|
||||||
|
|
||||||
def get_permission_codename(action, opts):
|
def get_permission_codename(action, opts):
|
||||||
|
|
Loading…
Reference in New Issue