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

22 views
Skip to first unread message

Django

unread,
Oct 25, 2023, 3:24:43 PM10/25/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
ColonelPhantom |
Type: Bug | Status: new
Component: | Version: 4.2
Uncategorized | 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 and #32975. A class references a proxy model,
and we define an inline for the proxied model. This fails with admin.E202
because Django does not recognize that the FK to the proxy model is the
same as an FK to the proxied model.

Assume models as follows:

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

class Journalist(Reporter):
class Meta:
proxy = True

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

and an admin as follows:
{{{
class ArticleInline(admin.TabularInline):
model = Article
fk_name = 'reporter'

@admin.register(Reporter)
class ReporterAdmin(admin.ModelAdmin):
inlines = [ArticleInline]
}}}

This will result in {{{<class 'testapp.admin.ArticleInline'>: (admin.E202)
fk_name 'reporter' is not a ForeignKey to 'testapp.Reporter'.}}}

The problem seems to be that the parent list does not include the model
itself, and as such Django does not recognize the equality here.

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

Django

unread,
Oct 25, 2023, 7:17:59 PM10/25/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
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 Asfand Yar Khan):

* component: Uncategorized => Database layer (models, ORM)


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

Django

unread,
Oct 25, 2023, 7:21:46 PM10/25/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
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
-------------------------------------+-------------------------------------

Comment (by Asfand Yar Khan):

Was able to reproduce this on my end.

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

Django

unread,
Oct 25, 2023, 7:26:04 PM10/25/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
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 Asfand Yar Khan):

* stage: Unreviewed => Accepted


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

Django

unread,
Oct 25, 2023, 11:39:39 PM10/25/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 4.2

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):

* component: Database layer (models, ORM) => contrib.admin


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

Django

unread,
Oct 31, 2023, 6:16:23 AM10/31/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: chenow
Type: Bug | Status: assigned

Component: contrib.admin | Version: 4.2
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 chenow):

* owner: nobody => chenow
* status: new => assigned


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

Django

unread,
Nov 1, 2023, 5:59:09 AM11/1/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: chenow
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
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 chenow):

* has_patch: 0 => 1


Comment:

Made a PR here: https://github.com/django/django/pull/17434

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

Django

unread,
Nov 2, 2023, 3:48:04 AM11/2/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: chenow
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage: Accepted
InlineModelAdmin, E202 |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1


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

Django

unread,
Nov 2, 2023, 5:43:41 AM11/2/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: chenow
Type: Bug | Status: assigned
Component: contrib.admin | Version: 4.2
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
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin


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

Django

unread,
Nov 2, 2023, 6:23:20 AM11/2/23
to django-...@googlegroups.com
#34927: ModelAdmin for model with InlineModelAdmin for proxy class reference
results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Quinten Kock | Owner: chenow
Type: Bug | Status: closed
Component: contrib.admin | Version: 4.2
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:"65c283be163212f5679b5edbd6a24c88b3af04ce" 65c283b]:
{{{
#!CommitTicketReference repository=""
revision="65c283be163212f5679b5edbd6a24c88b3af04ce"
Fixed #34927 -- Fixed admin system check for inlines with foreign keys to
proxy models.

Follow up to 0e8be73812a6e62d5a6b12a585d133b56bc2bf52.
}}}

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

Reply all
Reply to author
Forward
0 new messages