Opened 11 years ago
Closed 11 years ago
#23488 closed Bug (fixed)
Missing get_username in AnonymousUser
| Reported by: | Damien Baty | Owned by: | Damien Baty |
|---|---|---|---|
| Component: | contrib.auth | Version: | 1.7 |
| Severity: | Normal | Keywords: | |
| Cc: | Damien Baty | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | yes |
| Needs tests: | yes | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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) ?
Attachments (1)
Change History (4)
by , 11 years ago
| Attachment: | trac_23488_anonymoususer_get_username.patch added |
|---|
comment:1 by , 11 years ago
| Needs documentation: | set |
|---|---|
| Needs tests: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
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.
comment:3 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Yes, a test is required; see
django.contrib.auth.tests.test_basic / test_anonymous_user. And documentation here withversionaddedis a good idea. I don't think release notes are needed.