Don't use invalid backend from the Session to load the user in contrib.auth.get_user
|Reported by:||Tamas Szabo||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
django.contrib.auth saves the backend_path used to authenticate the user in the session.
This works great but when you remove the authorization backend you get an ImproperlyConfigured error.
The error references the old authorization backend so your first instinct is that the problem must be in your settings file.
I've been bitten by this a few times now, sometimes I remember to delete the Sessions manually, other times (like today) I think that my old settings.py must be executed and I go through the pain of deleting directories, redeploying and restarting servers.
I would like to suggest adding a check to the get_user call, that checks if the backend_path saved in the session is still in settings.AUTHORIZATION_BACKENDS.
If it isn't don't try to load it.
Patch for django.contrib.auth.init.py and tests included.
Change History (9)
comment:1 Changed 7 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Unreviewed → Accepted|