#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.38c334c67c2d5422a81cb5f1249e6019%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.