Fixed #21790 -- Removed reliance on an assert in auth.get_user().

Thanks matklad for the report.
This commit is contained in:
Tim Graham 2014-02-18 11:20:35 -05:00
parent 20f455b3d6
commit e1c8bc8fea
1 changed files with 8 additions and 6 deletions

View File

@ -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:
pass
else:
if backend_path in settings.AUTHENTICATION_BACKENDS:
backend = load_backend(backend_path) backend = load_backend(backend_path)
user = backend.get_user(user_id) or AnonymousUser() user = backend.get_user(user_id)
except (KeyError, AssertionError): return user or AnonymousUser()
user = AnonymousUser()
return user
def get_permission_codename(action, opts): def get_permission_codename(action, opts):