[Django] #23488: Missing get_username in AnonymousUser

6 views
Skip to first unread message

Django

unread,
Sep 15, 2014, 9:21:09 AM9/15/14
to django-...@googlegroups.com
#23488: Missing get_username in AnonymousUser
------------------------------+--------------------
Reporter: dbaty | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------
The documentation says that "`AnonymousUser` is a class that implements
the `django.contrib.auth.models.User` interface" [...] but `AnonymousUser`
does not define the `get_username()` method.

I am modifying some foreign code that calls `get_username()` without first
checking whether the user is authenticated or not. This may be bad
practice, but I would expect `AnonymousUser` and `User` to have the same
basic methods, including `get_username()`. It already has the `id`, `pk`
and `username` attributes, as well as the `groups` and `user_permissions`
accessors (that return empty sets).

Does that sound fine?

The changes are obvious. I cannot find any specific tests for the `*User`
models that I could augment, but I do not see the point of adding an
obvious unit test anyway. Would that need an addition in the documentation
as well (perhaps a "versionadded" block) ?

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

Django

unread,
Sep 15, 2014, 10:13:56 AM9/15/14
to django-...@googlegroups.com
#23488: Missing get_username in AnonymousUser
------------------------------+------------------------------------

Reporter: dbaty | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by timgraham):

* needs_docs: => 1
* stage: Unreviewed => Accepted
* needs_tests: => 1
* needs_better_patch: => 0


Comment:

Yes, a test is required; see `django.contrib.auth.tests.test_basic /
test_anonymous_user`. And documentation
[https://docs.djangoproject.com/en/dev/ref/contrib/auth/#django.contrib.auth.models.AnonymousUser
here] with `versionadded` is a good idea. I don't think release notes are
needed.

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

Django

unread,
Sep 18, 2014, 3:32:59 AM9/18/14
to django-...@googlegroups.com
#23488: Missing get_username in AnonymousUser
------------------------------+------------------------------------
Reporter: dbaty | Owner: dbaty
Type: Bug | Status: assigned
Component: contrib.auth | Version: 1.7

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

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


Comment:

How, seeing the `tests/` directory at the root, I missed the tests in
`django/contrib/auth/tests`...

A PR is here: https://github.com/django/django/pull/3235 that has tests
and documentation.

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

Django

unread,
Sep 18, 2014, 10:49:41 AM9/18/14
to django-...@googlegroups.com
#23488: Missing get_username in AnonymousUser
------------------------------+------------------------------------
Reporter: dbaty | Owner: dbaty
Type: Bug | Status: closed
Component: contrib.auth | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"ad491ecc6e20569a4f5c30a671a935f5c766a295"]:
{{{
#!CommitTicketReference repository=""
revision="ad491ecc6e20569a4f5c30a671a935f5c766a295"
Fixed #23488 -- Added AnonymousUser.get_username().
}}}

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

Reply all
Reply to author
Forward
0 new messages