[Django] #32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass reference results in admin.E202

9 views
Skip to first unread message

Django

unread,
Jul 30, 2021, 11:27:26 AM7/30/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas | Owner: nobody
Weyne |
Type: Bug | Status: new
Component: | Version: 3.1
contrib.admin | Keywords: proxy,
Severity: Normal | InlineModelAdmin, E202
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
This is similar to #30273, but in this case, the `InlineModelAdmin.model`
is a model with references to a proxy superclass

Assume the following Django models:

{{{#!python

class Reporter(models.Model):
name = models.CharField(max_length=50)


class Journalist(Reporter):

class Meta:
proxy = True


class SpecialJournalist(Journalist):

class Meta:
proxy = True


class Article(models.Model):
journalist = models.ForeignKey(Journalist, on_delete=models.CASCADE)
}}}


Register model admins as follows (exemplary):


{{{#!python

class ArticleInline(admin.TabularInline):
model = Article
fk_name = 'reporter'


@admin.register(SpecialJournalist)
class SpecialJournalistAdmin(admin.ModelAdmin):
inlines = [ArticleInline]

}}}


This will result in the following error:
{{{
<class 'ArticleInline'>: (admin.E202) fk_name 'journalist' is not a
ForeignKey to 'SpecialJournalist'.
}}}

This problem occurs on this check this check:
https://github.com/django/django/blob/3.1.13/django/forms/models.py#L1006

A `ValueError` is raised because the result for
`SpecialJournalist._meta.get_parent_list()` does not include `Journalist`:

{{{#!python
>>> SpecialJournalist._meta.get_parent_list()
[<class 'Reporter'>]
}}}

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

Django

unread,
Jul 30, 2021, 11:30:20 AM7/30/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage:
InlineModelAdmin, E202 | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "test30273-modified.zip" added.

Test project to see this error

Django

unread,
Jul 30, 2021, 11:30:48 AM7/30/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage:
InlineModelAdmin, E202 | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Lucas Weyne:

Old description:

New description:

{{{#!python


class Journalist(Reporter):


class SpecialJournalist(Journalist):


{{{#!python

}}}

{{{
>>> SpecialJournalist._meta.get_parent_list()
[<class 'Reporter'>]
}}}

--

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

Django

unread,
Jul 30, 2021, 11:31:45 AM7/30/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage:
InlineModelAdmin, E202 | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Lucas Weyne:

Old description:

> This is similar to #30273, but in this case, the `InlineModelAdmin.model`

> >>> SpecialJournalist._meta.get_parent_list()
> [<class 'Reporter'>]
> }}}

New description:

This is similar to #30273, but in this case, the `InlineModelAdmin.model`


is a model with references to a proxy superclass

Assume the following Django models:

{{{#!python

class Reporter(models.Model):
name = models.CharField(max_length=50)


class Journalist(Reporter):

class Meta:
proxy = True


class SpecialJournalist(Journalist):

class Meta:
proxy = True


class Article(models.Model):
journalist = models.ForeignKey(Journalist, on_delete=models.CASCADE)
}}}


Register model admins as follows (exemplary):


{{{#!python

class ArticleInline(admin.TabularInline):
model = Article

fk_name = 'journalist'


@admin.register(SpecialJournalist)
class SpecialJournalistAdmin(admin.ModelAdmin):
inlines = [ArticleInline]

}}}


This will result in the following error:
{{{
<class 'ArticleInline'>: (admin.E202) fk_name 'journalist' is not a
ForeignKey to 'SpecialJournalist'.
}}}

A `ValueError` is raised because the result for
`SpecialJournalist._meta.get_parent_list()` does not include `Journalist`:

{{{
>>> SpecialJournalist._meta.get_parent_list()
[<class 'Reporter'>]
}}}

--

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

Django

unread,
Aug 2, 2021, 12:43:14 AM8/2/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage: Accepted
InlineModelAdmin, E202 |
Has patch: 0 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


Comment:

Thanks for the report.

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

Django

unread,
Aug 2, 2021, 1:03:18 PM8/2/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: Bal
| Krishna Jha
Type: Bug | Status: assigned

Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage: Accepted
InlineModelAdmin, E202 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Bal Krishna Jha):

* owner: nobody => Bal Krishna Jha
* status: new => assigned


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

Django

unread,
Aug 14, 2021, 10:35:05 AM8/14/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: (none)
Type: Bug | Status: new

Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage: Accepted
InlineModelAdmin, E202 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Bal Krishna Jha):

* owner: Bal Krishna Jha => (none)
* status: assigned => new


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

Django

unread,
Aug 22, 2021, 7:25:22 PM8/22/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: Taulant
| Aliraj
Type: Bug | Status: assigned

Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage: Accepted
InlineModelAdmin, E202 |
Has patch: 0 | Needs documentation: 0

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

* owner: (none) => Taulant Aliraj


* status: new => assigned


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

Django

unread,
Aug 30, 2021, 1:03:48 PM8/30/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: Taulant
| Aliraj
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage: Accepted
InlineModelAdmin, E202 |
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

Opened a PR for this: https://github.com/django/django/pull/14812

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

Django

unread,
Sep 2, 2021, 4:38:32 AM9/2/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: Taulant
| Aliraj
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage: Accepted
InlineModelAdmin, E202 |
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/32975#comment:8>

Django

unread,
Sep 3, 2021, 1:19:30 AM9/3/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: Taulant
| Aliraj
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage: Ready for
InlineModelAdmin, E202 | checkin
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


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

Django

unread,
Sep 3, 2021, 1:20:30 AM9/3/21
to django-...@googlegroups.com
#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: Taulant
| Aliraj
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: fixed

Keywords: proxy, | Triage Stage: Ready for
InlineModelAdmin, E202 | 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:"0e8be73812a6e62d5a6b12a585d133b56bc2bf52" 0e8be738]:
{{{
#!CommitTicketReference repository=""
revision="0e8be73812a6e62d5a6b12a585d133b56bc2bf52"
Fixed #32975 -- Fixed admin system check for inlines with foreign keys to
proxy models.
}}}

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

Reply all
Reply to author
Forward
0 new messages