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 Abeer Upadhyay, 7 years ago

Owner: changed from nobody to Abeer Upadhyay
Status: newassigned

comment:2 by Abeer Upadhyay, 7 years ago

Has patch: set
Triage Stage: UnreviewedAccepted
Version 0, edited 7 years ago by Abeer Upadhyay (next)

comment:3 by Tim Graham, 7 years ago

Patch needs improvement: set
Summary: Better error message for passing authentication backend class where string expectedAdd an error message when passing an authentication backend class to login()'s backend argument where a string is expected
Type: New featureCleanup/optimization

comment:4 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 1bf4646f:

Fixed #29258 -- Added type checking for login()'s backend argument.

Note: See TracTickets for help on using tickets.
Back to Top