[Django] #33077: Wrong URL generated by get_admin_url for readonly field in custom Admin Site

7 views
Skip to first unread message

Django

unread,
Aug 31, 2021, 5:56:27 PM8/31/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
-----------------------------------------+------------------------
Reporter: Ken Whitesell | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
When a model containing a `ForeignKey` field is viewed (or edited) in a
custom Admin Site, and that `ForeignKey` field is listed in
`readonly_fields`, the url generated for the link is `/admin/...` instead
of `/custom-admin/...`.

This appears to be caused by the following line in
`django.contrib.admin.helpers` `get_admin_url`:
`url = reverse(url_name, args=[quote(remote_obj.pk)])`

Other parts of the admin use the `current_app` keyword parameter to
identify the correct current name of the Admin Site. (See
django.contrib.admin.options.ModelAdmin response_add as just one example)

I have been able to correct this specific issue by replacing the above
line with:
{{{
url = reverse(
url_name,
args=[quote(remote_obj.pk)],
current_app=self.model_admin.admin_site.name
)
}}}

However, I don't know if there are any side effects and I have not yet run
the full suite of tests on this. Mostly looking for feedback whether I'm
on the right track.

--
Ticket URL: <https://code.djangoproject.com/ticket/33077>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 1, 2021, 4:09:42 AM9/1/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+------------------------------------

Reporter: Ken Whitesell | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Carlton Gibson):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Hey Ken, yes seems right. Good spot.

Looks like this should have been part of
b79088306513d5ed76d31ac40ab3c15f858946ea for #31181 (which was Django
3.2)
[https://github.com/django/django/commit/b79088306513d5ed76d31ac40ab3c15f858946ea
#diff-07734f3e730920ea3922e6de9cb783825f009817b53e16ece8c3c2e3fdb41e40R199
here].

> However, I don't know if there are any side effects and I have not yet
run the full suite of tests on this. Mostly looking for feedback whether
I'm on the right track.

I ran your suggestion against most of the ''usual suspects'' `admin_*`
tests without issue so...

Would you like to prepare a patch? Looks like setting up the test case is
the most of it...

Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:1>

Django

unread,
Sep 1, 2021, 8:02:16 PM9/1/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+------------------------------------

Reporter: Ken Whitesell | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Ken Whitesell):

I'll be happy to try - but I'm not likely to be able to get to it before
the weekend. (I don't know how "urgent" you consider it.) If it can sit
that long, I'll see what I can do. (First "real patch" and all that - want
to make sure I do it reasonably right.)

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:2>

Django

unread,
Sep 2, 2021, 2:54:43 AM9/2/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+-----------------------------------------
Reporter: Ken Whitesell | Owner: Ken Whitesell
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Carlton Gibson):

* owner: nobody => Ken Whitesell
* status: new => assigned


Comment:

Hey Ken. Super thanks!

Since it's a ''bug in a new feature'' it's marked as release blocker and
will be backported to Django 3.2.
We'll target [https://docs.djangoproject.com/en/dev/releases/3.2.8/ 3.2.8,
which is slated for the beginning of October].
If it gets close to that and you've not had time we can pick it up.

Reach out on the Forum if you'd like input at all. 🙂

Thanks! (And Welcome Aboard! ⛵️)

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:3>

Django

unread,
Sep 3, 2021, 6:58:12 AM9/3/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
-------------------------------------+-------------------------------------
Reporter: Ken Whitesell | Owner: Abhijith
| Ganesh
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Abhijith Ganesh):

* owner: Ken Whitesell => Abhijith Ganesh


--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:4>

Django

unread,
Sep 3, 2021, 6:59:20 AM9/3/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
-------------------------------------+-------------------------------------
Reporter: Ken Whitesell | Owner: Abhijith
| Ganesh
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Abhijith Ganesh):

Heyy folks, I wanted to assign the ticket to myself and fix the issue,
instead it assigned the ownership to me. Apologies

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:5>

Django

unread,
Sep 3, 2021, 7:07:44 AM9/3/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+-----------------------------------------
Reporter: Ken Whitesell | Owner: Ken Whitesell
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Abhijith Ganesh):

* owner: Abhijith Ganesh => Ken Whitesell


Comment:

Changes ownership again.

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:6>

Django

unread,
Sep 3, 2021, 8:18:46 AM9/3/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+-----------------------------------------
Reporter: Ken Whitesell | Owner: Ken Whitesell
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------

Comment (by Abhijith Ganesh):

I am trying to assign this to myself. So forgive me if I commit a message.

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:7>

Django

unread,
Sep 4, 2021, 4:16:50 AM9/4/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+-----------------------------------------
Reporter: Ken Whitesell | Owner: Ken Whitesell
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------

Comment (by Carlton Gibson):

Hi Abhijith — just to confirm, according to the discussion Ken is
currently working on this ticket, so let's give him a window to do that
before re-assigning it. Thanks! (I think that's the conclusion you came
to, but just double-checking so you don't both work on the same ticket at
the same time.)

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:8>

Django

unread,
Sep 16, 2021, 4:54:30 AM9/16/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+-----------------------------------------
Reporter: Ken Whitesell | Owner: Ken Whitesell
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14855 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:9>

Django

unread,
Sep 17, 2021, 10:20:53 PM9/17/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+------------------------------------
Reporter: Ken Whitesell | Owner: (none)

Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Ken Whitesell):

* owner: Ken Whitesell => (none)
* status: assigned => new


Comment:

Sorry, I just can't seem to get the hang of working with git the way you
want things done. I'm removing my self from the ticket so that it's
available for anyone else wanting to move forward with it.

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:10>

Django

unread,
Sep 18, 2021, 4:37:55 AM9/18/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
---------------------------------+------------------------------------
Reporter: Ken Whitesell | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Carlton Gibson):

Hey Ken. No problem. The PR is essentially there. Mariusz or I can pick
it up to make the small edits and rebase etc. Thanks for the report and
the fix. Welcome aboard!

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:11>

Django

unread,
Sep 18, 2021, 6:29:57 AM9/18/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
-------------------------------------+-------------------------------------

Reporter: Ken Whitesell | Owner: Ken
| Whitesell
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: (none) => Ken Whitesell
* needs_better_patch: 1 => 0


* status: new => assigned

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:12>

Django

unread,
Sep 18, 2021, 2:10:04 PM9/18/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
-------------------------------------+-------------------------------------
Reporter: Ken Whitesell | Owner: Ken
| Whitesell
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"0a9aa02e6f1d1b9ceca155d281a2be624bb1d3a2" 0a9aa02e]:
{{{
#!CommitTicketReference repository=""
revision="0a9aa02e6f1d1b9ceca155d281a2be624bb1d3a2"
Fixed #33077 -- Fixed links to related models for admin's readonly fields
in custom admin site.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:13>

Django

unread,
Sep 18, 2021, 2:10:43 PM9/18/21
to django-...@googlegroups.com
#33077: Wrong URL generated by get_admin_url for readonly field in custom Admin
Site
-------------------------------------+-------------------------------------
Reporter: Ken Whitesell | Owner: Ken
| Whitesell
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"d4a587a5fac5fbda4e5688029d8c4cb04bf81c36" d4a587a5]:
{{{
#!CommitTicketReference repository=""
revision="d4a587a5fac5fbda4e5688029d8c4cb04bf81c36"
[3.2.x] Fixed #33077 -- Fixed links to related models for admin's readonly


fields in custom admin site.

Backport of 0a9aa02e6f1d1b9ceca155d281a2be624bb1d3a2 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33077#comment:14>

Reply all
Reply to author
Forward
0 new messages