Opened 6 years ago

Closed 6 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 Changed 6 years ago by Abeer Upadhyay

Owner: changed from nobody to Abeer Upadhyay
Status: newassigned

comment:2 Changed 6 years ago by Abeer Upadhyay

Has patch: set
Triage Stage: UnreviewedAccepted
Last edited 6 years ago by Tim Graham (previous) (diff)

comment:3 Changed 6 years ago by Tim Graham

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 Changed 6 years ago by Tim Graham <timograham@…>

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