[Django] #28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup lookup with foreign key as primary

49 views
Skip to first unread message

Django

unread,
Jul 11, 2017, 6:20:38 AM7/11/17
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary
--------------------------------------------+------------------------
Reporter: elliott-omosheye | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.11
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 |
--------------------------------------------+------------------------
Wrote a failing test to demonstrate - same test/code passes on 1.8
{{{
@isolate_apps('modeladmin')
def test_lookup_allowed_foreign_primary(self):

class Country(models.Model):
name = models.CharField(max_length=256)

class Place(models.Model):
country = models.ForeignKey(Country, models.CASCADE)

class Restaurant(models.Model):
place = models.OneToOneField(Place, models.CASCADE,
primary_key=True)

class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant, models.CASCADE)

class WaiterAdmin(ModelAdmin):
list_filter = [
'restaurant__place__country',
]

ma = WaiterAdmin(Waiter, self.site)
self.assertIs(ma.lookup_allowed('restaurant__place__country',
'test_value'), True)
}}}

I think this is caused by the admin thinking that having a foreign key
field as a primary key is the same as concrete inheritance. So when you
try and check lookups for {{{restaurant__place__country}}} it thinks
'place' is the concrete parent of 'restaurant' and shortcuts it to
{{{restaurant__country}}} which isn't in 'list_filter'. And you can't add
{{{restaurant__country}}} to list_filter because country isn't actually on
restaurant.

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

Django

unread,
Jul 11, 2017, 10:00:26 AM7/11/17
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+------------------------------------

Reporter: elliott-omosheye | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.11
Severity: Normal | 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 Tim Graham):

* stage: Unreviewed => Accepted


Old description:

New description:

Wrote a failing test for `tests/modeladmin/tests.py` to demonstrate - same

--

Comment:

Bisected to 8f30556329b64005d63b66859a74752a0b261315.

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

Django

unread,
Aug 10, 2017, 6:06:18 AM8/10/17
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+----------------------------------------
Reporter: elliott-omosheye | Owner: Windson yang
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11

Severity: Normal | 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 Windson yang):

* status: new => assigned
* owner: nobody => Windson yang


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

Django

unread,
Mar 16, 2023, 5:41:34 AM3/16/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+------------------------------------

Reporter: elliott-omosheye | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.11
Severity: Normal | 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 Mariusz Felisiak):

* cc: Sarah Boyce (added)

Django

unread,
Mar 18, 2023, 5:28:08 AM3/18/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+---------------------------------------
Reporter: elliott-omosheye | Owner: Sarah Boyce
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* owner: nobody => Sarah Boyce


* status: new => assigned

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/16661

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

Django

unread,
Mar 18, 2023, 7:23:43 AM3/18/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+---------------------------------------
Reporter: elliott-omosheye | Owner: Sarah Boyce
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11

Severity: Normal | 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 Sarah Boyce):

* needs_better_patch: 0 => 1


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

Django

unread,
Mar 18, 2023, 5:32:39 PM3/18/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+---------------------------------------
Reporter: elliott-omosheye | Owner: Sarah Boyce
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0


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

Django

unread,
Mar 21, 2023, 5:13:19 AM3/21/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+---------------------------------------
Reporter: elliott-omosheye | Owner: Sarah Boyce
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11

Severity: Normal | 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


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

Django

unread,
Mar 23, 2023, 2:28:09 AM3/23/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+---------------------------------------
Reporter: elliott-omosheye | Owner: Sarah Boyce
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0


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

Django

unread,
Mar 27, 2023, 4:08:24 AM3/27/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+---------------------------------------
Reporter: elliott-omosheye | Owner: Sarah Boyce
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11

Severity: Normal | 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


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

Django

unread,
Mar 27, 2023, 1:16:33 PM3/27/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
----------------------------------+---------------------------------------
Reporter: elliott-omosheye | Owner: Sarah Boyce
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0


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

Django

unread,
Mar 28, 2023, 3:21:53 AM3/28/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
-------------------------------------+-------------------------------------

Reporter: elliott-omosheye | Owner: Sarah
| Boyce
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.11
Severity: Normal | 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):

* stage: Accepted => Ready for checkin


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

Django

unread,
Mar 28, 2023, 4:11:50 AM3/28/23
to django-...@googlegroups.com
#28384: ModelAdmin.lookup_allowed() incorrectly raises DisallowedModelAdminLookup
lookup with foreign key as primary key
-------------------------------------+-------------------------------------
Reporter: elliott-omosheye | Owner: Sarah
| Boyce
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.11
Severity: Normal | 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:"45ecd9acca9b36093e274f47b6877a5f79108d9e" 45ecd9ac]:
{{{
#!CommitTicketReference repository=""
revision="45ecd9acca9b36093e274f47b6877a5f79108d9e"
Fixed #28384 -- Fixed ModelAdmin.lookup_allowed() for OneToOneField
primary keys and nested relations.
}}}

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

Reply all
Reply to author
Forward
0 new messages