Opened 2 years ago

Closed 22 months 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

Description

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 23 months ago by timo

  • Component changed from Uncategorized to contrib.auth
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from contrib.auth.models.AbstractUser get_absolute_url should call get_username to Remove contrib.auth.models.AbstractUser arbitrary definition of get_absolute_url
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

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/tests.py", line 1755, in test_shortcut_view_only_available_to_staff
    self.assertEqual(response.status_code, 302)
AssertionError: 404 != 302

comment:2 Changed 22 months ago by timo

  • Has patch set

comment:3 Changed 22 months ago by claudep

  • Triage Stage changed from Accepted to Ready for checkin

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

  • Resolution set to fixed
  • Status changed from new to closed

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