[Django] #29258: Better error message for passing authentication backend class where string expected

33 views
Skip to first unread message

Django

unread,
Mar 25, 2018, 1:37:31 AM3/25/18
to django-...@googlegroups.com
#29258: Better error message for passing authentication backend class where string
expected
-----------------------------------------+------------------------
Reporter: Ryan Govostes | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29258>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 25, 2018, 2:35:04 AM3/25/18
to django-...@googlegroups.com
#29258: Better error message for passing authentication backend class where string
expected
-------------------------------+------------------------------------------
Reporter: Ryan Govostes | Owner: Abeer Upadhyay
Type: New feature | Status: assigned
Component: contrib.auth | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------------
Changes (by Abeer Upadhyay):

* status: new => assigned
* owner: nobody => Abeer Upadhyay


--
Ticket URL: <https://code.djangoproject.com/ticket/29258#comment:1>

Django

unread,
Mar 25, 2018, 11:39:22 AM3/25/18
to django-...@googlegroups.com
#29258: Better error message for passing authentication backend class where string
expected
-------------------------------+------------------------------------------
Reporter: Ryan Govostes | Owner: Abeer Upadhyay
Type: New feature | Status: assigned
Component: contrib.auth | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------------
Changes (by Abeer Upadhyay):

* has_patch: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/29258#comment:2>

Django

unread,
Mar 26, 2018, 10:49:14 AM3/26/18
to django-...@googlegroups.com
#29258: Add an error message when passing an authentication backend class to
login()'s backend argument where a string is expected
-------------------------------------+-------------------------------------

Reporter: Ryan Govostes | Owner: Abeer
Type: | Upadhyay
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* type: New feature => Cleanup/optimization


--
Ticket URL: <https://code.djangoproject.com/ticket/29258#comment:3>

Django

unread,
Mar 28, 2018, 10:41:40 AM3/28/18
to django-...@googlegroups.com
#29258: Add an error message when passing an authentication backend class to
login()'s backend argument where a string is expected
-------------------------------------+-------------------------------------
Reporter: Ryan Govostes | Owner: Abeer
Type: | Upadhyay
Cleanup/optimization | Status: closed
Component: contrib.auth | Version: 2.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"1bf4646f9133f26547a0dccf2f8a4526d85f2ab3" 1bf4646f]:
{{{
#!CommitTicketReference repository=""
revision="1bf4646f9133f26547a0dccf2f8a4526d85f2ab3"
Fixed #29258 -- Added type checking for login()'s backend argument.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29258#comment:4>

Reply all
Reply to author
Forward
0 new messages