Opened 7 years ago
Closed 7 years ago
#29258 closed Cleanup/optimization (fixed)
Add an error message when passing an authentication backend class to login()'s backend argument where a string is expected
Reported by: | Ryan Govostes | Owned by: | Abeer Upadhyay |
---|---|---|---|
Component: | contrib.auth | Version: | 2.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
I had written
from django.contrib.auth.backends import ModelBackend ... login(request, user, backend=ModelBackend)
which generated a very bizarre exception "Object of type 'type' is not JSON serializable" from the sessions middleware with no backtrace leading back to my code.
In the documentation for "Selecting the authentication backend", it says: "the value of the backend argument or the user.backend attribute should be a dotted import path string (like that found in AUTHENTICATION_BACKENDS), not the actual backend class."
It would be nice to catch this, e.g., assert isinstance(backend, str)
closer to the site of the mistake.
Change History (4)
comment:1 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 7 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 7 years ago
Patch needs improvement: | set |
---|---|
Summary: | Better error message for passing authentication backend class where string expected → Add an error message when passing an authentication backend class to login()'s backend argument where a string is expected |
Type: | New feature → Cleanup/optimization |
PR