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.
* 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>
* 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>
* 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>