[Django] #22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin

107 views
Skip to first unread message

Django

unread,
Feb 13, 2014, 4:41:55 AM2/13/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
-------------------------------+--------------------
Reporter: jwa | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Keywords: checks
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Checks `admin.E202` fail when trying to detect a `ForeignKey` from a
`GenericInlineModelAdmin`:

The following setup yields this error:

{{{
<class 'app.admin.BarInline'>: (admin.E202) 'app.Bar' has no ForeignKey to
'app.Foo'.
}}}

`models.py`
{{{
class Foo(models.Model):
"""Foo may have some Bars."""
text = models.TextField()

class Bar(models.Model):
text = models.TextField()

content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type',
'object_id')
}}}

`admin.py`
{{{
class BarInline(GenericStackedInline):
model = Bar

@admin.register(Foo)
class FooAdmin(admin.ModelAdmin):
inlines = [BarInline]
}}}

I think this will require an exception in `_check_fk_name` for generic
InlineAdmin classes here:
https://github.com/django/django/blob/06bd181f97e5e5561ae7e80efae4c38ee670773f/django/contrib/admin/checks.py#L866

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

Django

unread,
Feb 15, 2014, 6:45:43 AM2/15/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
-------------------------------+--------------------------------------

Reporter: jwa | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: checks | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I've 3 errors:

{{{#!bash


<class 'app.admin.BarInline'>: (admin.E202) 'app.Bar' has no ForeignKey to
'app.Foo'.

Bar.content_object: (contenttypes.E001) The field refers to
"Bar.object_id" field which is missing.
Bar.content_object: (contenttypes.E005) The field refers to
Bar.content_type field which is missing.
}}}

But {{{object_id}}} and {{{content_type}}} fields are in my database.

Note for **@jwa**: {{{contenttypes.generic}}} has been deprecated
(https://github.com/django/django/commit/10e3faf191d8f230dde8534d1c8fad8c8717816e)

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

Django

unread,
Feb 15, 2014, 6:51:05 PM2/15/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
---------------------------------+------------------------------------

Reporter: jwa | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Release blocker | Resolution:
Keywords: checks | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


Comment:

This is a newly added system check, so it's a release blocker.

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

Django

unread,
Feb 22, 2014, 3:10:58 PM2/22/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
---------------------------------+------------------------------------
Reporter: jwa | Owner: josven
Type: Bug | Status: assigned
Component: contrib.admin | Version: master

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

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

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


Comment:

These is a PR: https://github.com/django/django/pull/2351
I'm introducing dependency to
django.contrib.contenttypes.fields.GenericForeignKey.
Don't know if this is acceptable or not.

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

Django

unread,
Feb 23, 2014, 12:13:38 PM2/23/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
---------------------------------+------------------------------------
Reporter: jwa | Owner: josven
Type: Bug | Status: assigned
Component: contrib.admin | Version: master

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

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

Comment (by josven):

Changed the approach.
- Created a GenericInlineModelAdminChecks that override def
_check_fk_name.
- Moved the dependency for django.contrib.contenttypes in
django.conrtib.admin.checks, to having a dependency for
django.contrib.admin.checks in django.contrib.contenttypes.checks instead.

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

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

Django

unread,
Feb 23, 2014, 1:18:33 PM2/23/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
---------------------------------+------------------------------------
Reporter: jwa | Owner: josven
Type: Bug | Status: assigned
Component: contrib.admin | Version: master

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

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

Comment (by josven):

The lastest approach did not completely work. The previous commit
https://github.com/josven/django/commit/b697147d0b9e4b762aae7b2c057231894d6098c2
still works.

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

Django

unread,
Feb 27, 2014, 4:30:48 PM2/27/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
---------------------------------+------------------------------------
Reporter: jwa | Owner: josven
Type: Bug | Status: assigned
Component: contrib.admin | Version: master

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

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

Comment (by CollinAnderson):

I can confirm that the current pull request doesn't fix it but
https://github.com/josven/django/commit/b697147 works for me.

As far as the dependency goes, could we have a `Inline._check_fk()` on all
inlines that lazy-imports code to handle the check?

Or, have a hook like `Inline._checks =
'django.contrib.contenttypes.checks.GenericInlineModelAdminChecks'`

As a side note, I like to do hacky things with my inlines (like store data
in json on the original model) and sometimes that means it doesn't make
sense to have an actual foreign key.

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

Django

unread,
Mar 7, 2014, 10:23:09 PM3/7/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
---------------------------------+------------------------------------
Reporter: jwa | Owner: josven
Type: Bug | Status: assigned
Component: contrib.admin | Version: master

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

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

Comment (by russellm):

The problem here is that GenericInlineModelAdmin is using the base
InlineModelAdmin checks. We just need to make GenericInlineModelAdmin run
it's own, generic-specific checks of the relation to the parent.

I'm working on a patch, incoming shortly.

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

Django

unread,
Mar 7, 2014, 10:26:04 PM3/7/14
to django-...@googlegroups.com
#22034: Checks for ModelAdmin ForeignKeys fail with GenericInlineModelAdmin
---------------------------------+------------------------------------
Reporter: jwa | Owner: josven
Type: Bug | Status: closed
Component: contrib.admin | Version: master
Severity: Release blocker | Resolution: fixed

Keywords: checks | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Russell Keith-Magee <russell@…>):

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


Comment:

In [changeset:"70ec4d776ef0e68960ccee21476b8654e9399f53"]:
{{{
#!CommitTicketReference repository=""
revision="70ec4d776ef0e68960ccee21476b8654e9399f53"
Fixed #22034 -- Added a specific set of relation checks for
GenericInlineModelAdmin.

Thanks to jwa for the report.
}}}

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

Reply all
Reply to author
Forward
0 new messages