[Django] #28420: Document CallableBool behaviour

9 views
Skip to first unread message

Django

unread,
Jul 21, 2017, 12:06:33 AM7/21/17
to django-...@googlegroups.com
#28420: Document CallableBool behaviour
-----------------------------------------+-------------------------------
Reporter: Tobi | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.auth | Version: 1.11
Severity: Normal | Keywords: documentation
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+-------------------------------
I have just run into the issue described in
https://code.djangoproject.com/ticket/26988, trying to check identity
rather then equality on `User.is_authenticated`.

The
[https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.User.is_authenticated
documentation] for this attribute is misleading. It implies that that
`is_authenticated` **is** `True` for authenticated users, while in reality
the attribute has to be called or checked for equality (`==`) :

Read-only attribute which is always True (as opposed to
AnonymousUser.is_authenticated which is always False).

I suggest to add a notice/warning to the documentation, that use of *is* /
identity checking is not yet supported. There's a similar warning in the
deprecation notice for `User.is_authenticated()`
[https://docs.djangoproject.com/en/1.11/releases/1.10/#user-is-auth-anon-
deprecation here], but neither the warning nor the deprecation notice can
be found in the documentation for
`contrib.auth.models.User.is_authenticated`

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

Django

unread,
Jul 21, 2017, 12:10:40 AM7/21/17
to django-...@googlegroups.com
#28420: Document CallableBool behaviour
-------------------------------+--------------------------------------

Reporter: Tobi | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:

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

* component: contrib.auth => Documentation


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

Django

unread,
Jul 21, 2017, 6:25:49 AM7/21/17
to django-...@googlegroups.com
#28420: Document CallableBool comparison restriction for User.is_authenticated /
is_anonymous
--------------------------------------+------------------------------------
Reporter: Tobi | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: documentation | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted
* type: Uncategorized => Cleanup/optimization


Comment:

It's more Python to write `if request.user.is_authenticated:` or `if not
request.user.is_authenticated:` rather than `== True` but a note wouldn't
hurt.

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

Django

unread,
Jul 22, 2017, 4:14:21 PM7/22/17
to django-...@googlegroups.com
#28420: Document CallableBool comparison restriction for User.is_authenticated /
is_anonymous
--------------------------------------+------------------------------------
Reporter: Tobi | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: documentation | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tobi):

Replying to [comment:2 Tim Graham]:


> It's more Python to write `if request.user.is_authenticated:` or `if not
request.user.is_authenticated:` rather than `== True` but a note wouldn't
hurt.

True, `== True:` is less Python, but this one does actually work. The
problem is that `if request.user.is_authenticated is True:` and `if
request.user.is_authenticated:` yield different results:

{{{
>>> AnonymousUser().is_authenticated is True
False
>>> AnonymousUser().is_authenticated is False
False
>>> if AnonymousUser().is_authenticated:
... print('Authed')
...
>>>
}}}

So different to the documentation `is_authenticated` is not an attribute
which *is* always `True` (or `False` for `AnonymousUser`), but its return
type has to be called when used with `is`, which would be the pythonic way
to check here (as `if not is_authenticated` would also catch `None`, `0`,
`''` `[]` etc).

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

Django

unread,
Jul 22, 2017, 4:37:39 PM7/22/17
to django-...@googlegroups.com
#28420: Document CallableBool comparison restriction for User.is_authenticated /
is_anonymous
--------------------------------------+------------------------------------
Reporter: Tobi | Owner: Tobi
Type: Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: documentation | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tobi):

* owner: nobody => Tobi
* status: new => assigned


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

Django

unread,
Jul 24, 2017, 9:36:13 AM7/24/17
to django-...@googlegroups.com
#28420: Document CallableBool comparison restriction for User.is_authenticated /
is_anonymous
--------------------------------------+------------------------------------
Reporter: Tobi | Owner: Tobi
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: documentation | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/8799 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28420#comment:5>

Django

unread,
Jul 24, 2017, 1:45:03 PM7/24/17
to django-...@googlegroups.com
#28420: Document CallableBool comparison restriction for User.is_authenticated /
is_anonymous
--------------------------------------+------------------------------------
Reporter: Tobi | Owner: Tobi
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: fixed

Keywords: documentation | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"aef117eb2e7805c5965adbfbfe1b5374cb58bbbe" aef117e]:
{{{
#!CommitTicketReference repository=""
revision="aef117eb2e7805c5965adbfbfe1b5374cb58bbbe"
[1.11.x] Fixed #28420 -- Doc'd 'is' comparison restriction for
User.is_authenticated/anonymous.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28420#comment:6>

Reply all
Reply to author
Forward
0 new messages