Opened 4 years ago

Closed 4 years ago

#20881 closed Bug (fixed)

Remove contrib.auth.models.AbstractUser arbitrary definition of get_absolute_url

Reported by: anentropic Owned by: nobody
Component: contrib.auth Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


In AbstractUser class there is this code:

    def get_absolute_url(self):
        return "/users/%s/" % urlquote(self.username)

Firstly... I cannot see where this url pattern is defined - it's not in contrib.auth.urls - possibly this method should just be deleted from the class?

Secondly, if this url is defined somewhere and needed, I think the code should be:

    def get_absolute_url(self):
        return "/users/%s/" % urlquote(self.get_username())

I am happy to knock up a patch but would like to check I haven't misunderstood first.

Change History (4)

comment:1 Changed 4 years ago by Tim Graham

Component: Uncategorizedcontrib.auth
Summary: contrib.auth.models.AbstractUser get_absolute_url should call get_usernameRemove contrib.auth.models.AbstractUser arbitrary definition of get_absolute_url
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

I don't see any good reason for having this defined on AbstractUser. For any site that doesn't implement a corresponding user view, this will create a broken "View on site" link in the admin. I think it's fine to remove it without a deprecation (open to objections), but it'll need a mention in the "backwards incompatible changes" section of the release notes.

If we remove the method, one test will need to be updated to use a different model:

FAIL: test_shortcut_view_only_available_to_staff (admin_views.tests.SecureViewTests)
Traceback (most recent call last):
  File "/home/timgraham/code/django/tests/admin_views/", line 1755, in test_shortcut_view_only_available_to_staff
    self.assertEqual(response.status_code, 302)
AssertionError: 404 != 302

comment:2 Changed 4 years ago by Tim Graham

Has patch: set

comment:3 Changed 4 years ago by Claude Paroz

Triage Stage: AcceptedReady for checkin

comment:4 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In cf8d6e910839238ee9b2d0a094d98cb8d48dc530:

Fixed #20881 -- Removed contrib.auth.models.AbstractUser.get_absolute_url()

The definition is arbitrary and creates a broken "view on site"
link in the admin if a project doesn't define such a URL.

Note: See TracTickets for help on using tickets.
Back to Top