[Django] #28418: Creating join paths to fields that are GenericRelations to proxy models fails with an AttributeError

4 views
Skip to first unread message

Django

unread,
Jul 20, 2017, 2:00:59 PM7/20/17
to django-...@googlegroups.com
#28418: Creating join paths to fields that are GenericRelations to proxy models
fails with an AttributeError
------------------------------------------------+------------------------
Reporter: Rachel Tobin | Owner: nobody
Type: Bug | Status: new
Component: contrib.contenttypes | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
This appears to be a regression introduced by
https://code.djangoproject.com/ticket/12885. When attempting to build
joins for a GenericRelation field that points to a proxy model, an
AttributeError is caused via {{{contrib/contenttypes/fields.py:375}}} ,
when trying to get the ancestor of the proxy model's parent. Since the
proxy model's parent does not have an ancestor, None is returned and
{{{contrib/contenttypes/fields.py:377}}} raises an AttributeError, given
that `field` is None.

As an example:

{{{
class GenericConcreteModel(models.Model):
content_type = models.ForeignKey(ContentType,
on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey()


class GenericProxyModel(GenericConcreteModel):
class Meta:
proxy = True


class GenericRelationProxyModel(models.Model):
proxy_model = GenericRelation('GenericProxyModel')
}}}

Where the query
{{{
GenericRelationProxyModel.objects.filter(proxy_model__content_type=ContentType.objects.get(id=1))
}}}
will cause an attribute error.

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

Django

unread,
Jul 20, 2017, 2:17:19 PM7/20/17
to django-...@googlegroups.com
#28418: Creating join paths to fields that are GenericRelations to proxy models
fails with an AttributeError
-------------------------------------+-------------------------------------

Reporter: Rachel Tobin | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Rachel Tobin:

Old description:

> This appears to be a regression introduced by
> https://code.djangoproject.com/ticket/12885. When attempting to build
> joins for a GenericRelation field that points to a proxy model, an
> AttributeError is caused via {{{contrib/contenttypes/fields.py:375}}} ,
> when trying to get the ancestor of the proxy model's parent. Since the
> proxy model's parent does not have an ancestor, None is returned and
> {{{contrib/contenttypes/fields.py:377}}} raises an AttributeError, given
> that `field` is None.
>
> As an example:
>
> {{{
> class GenericConcreteModel(models.Model):
> content_type = models.ForeignKey(ContentType,
> on_delete=models.CASCADE)
> object_id = models.PositiveIntegerField()
> content_object = GenericForeignKey()
>

> class GenericProxyModel(GenericConcreteModel):
> class Meta:
> proxy = True
>

> class GenericRelationProxyModel(models.Model):
> proxy_model = GenericRelation('GenericProxyModel')
> }}}
>
> Where the query
> {{{
> GenericRelationProxyModel.objects.filter(proxy_model__content_type=ContentType.objects.get(id=1))
> }}}
> will cause an attribute error.

New description:

This appears to be a regression introduced by
https://code.djangoproject.com/ticket/12885. When attempting to build
joins for a GenericRelation field that points to a proxy model, an
AttributeError is caused via {{{contrib/contenttypes/fields.py:375}}} ,
when trying to get the ancestor of the proxy model's parent. Since the
proxy model's parent does not have an ancestor, None is returned and
{{{contrib/contenttypes/fields.py:377}}} raises an AttributeError, given
that `field` is None.

As an example:

{{{
class GenericConcreteModel(models.Model):
content_type = models.ForeignKey(ContentType,
on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey()


class GenericProxyModel(GenericConcreteModel):
class Meta:
proxy = True


class GenericRelationProxyModel(models.Model):
proxy_model = GenericRelation('GenericProxyModel')
}}}

Where the query
{{{
GenericRelationProxyModel.objects.filter(proxy_model__content_type=ContentType.objects.get(id=1))
}}}
will cause an attribute error.

I have made a patch and submitted the PR
https://github.com/django/django/pull/8792 to fix this issue.

--

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

Django

unread,
Jul 20, 2017, 2:41:35 PM7/20/17
to django-...@googlegroups.com
#28418: Creating join paths to fields that are GenericRelations to proxy models
fails with an AttributeError
--------------------------------------+------------------------------------

Reporter: Rachel Tobin | Owner: nobody
Type: Bug | Status: new
Component: contrib.contenttypes | Version: master
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 Simon Charette):

* version: 1.11 => master
* stage: Unreviewed => Accepted


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

Django

unread,
Jul 21, 2017, 6:21:27 PM7/21/17
to django-...@googlegroups.com
#28418: Creating join paths to fields that are GenericRelations to proxy models
fails with an AttributeError
--------------------------------------+------------------------------------

Reporter: Rachel Tobin | Owner: nobody
Type: Bug | Status: closed
Component: contrib.contenttypes | Version: master
Severity: Normal | Resolution: fixed
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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"f9e5f9ae9f83c7ddf5e5d3c369b6bf54a9b80ab5" f9e5f9a]:
{{{
#!CommitTicketReference repository=""
revision="f9e5f9ae9f83c7ddf5e5d3c369b6bf54a9b80ab5"
Fixed #28418 -- Fixed queryset crash when using a GenericRelation to a
proxy model.
}}}

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

Django

unread,
Jul 21, 2017, 6:32:36 PM7/21/17
to django-...@googlegroups.com
#28418: Creating join paths to fields that are GenericRelations to proxy models
fails with an AttributeError
--------------------------------------+------------------------------------

Reporter: Rachel Tobin | Owner: nobody
Type: Bug | Status: closed
Component: contrib.contenttypes | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"801b6fb32e36a9b61ae469e29e17650dd8afd9fe" 801b6fb3]:
{{{
#!CommitTicketReference repository=""
revision="801b6fb32e36a9b61ae469e29e17650dd8afd9fe"
[1.11.x] Fixed #28418 -- Fixed queryset crash when using a GenericRelation
to a proxy model.

Backport of f9e5f9ae9f83c7ddf5e5d3c369b6bf54a9b80ab5 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages