[Django] #29612: prefetch_related on GenericRelations not

7 views
Skip to first unread message

Django

unread,
Jul 30, 2018, 11:43:24 AM7/30/18
to django-...@googlegroups.com
#29612: prefetch_related on GenericRelations not
-------------------------------------+-------------------------------------
Reporter: obayemi | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) | Keywords: GenericForeignKey
Severity: Normal | GenericRelation Prefetch
Triage Stage: | prefetch_related
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
with two models joined with a generic foreignkey / relationship, if we
prefetch the generic relation, its cache will not be invalidated by
updates ({{{.add}}}, {{{.remove}}} nor {{{.all().delete()}}})
{{{
class Foo(models.Model):
tags = GenericRelation("TaggedItem")

class TaggedItem(models.Model):
tag = models.SlugField()
content_type = models.ForeignKey(ContentType,
on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey("content_type", "object_id")
}}}
{{{
Foo.objects.create()
f = Foo.objects.prefetch_related('tags').last()
a = TaggedItem(tag='tag')
print(f.tags.all())
f.tags.add(a, bulk=False)
print(f.tags.all())
}}}
will give
{{{
<QuerySet []>
<QuerySet []>
}}}

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

Django

unread,
Jul 30, 2018, 11:56:16 AM7/30/18
to django-...@googlegroups.com
#29612: prefetch_related on GenericRelations not
--------------------------------------+------------------------------------

Reporter: obayemi | Owner: nobody
Type: Bug | Status: new
Component: contrib.contenttypes | Version: master
Severity: Normal | Resolution:
Keywords: prefetch_related | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

* keywords: GenericForeignKey GenericRelation Prefetch prefetch_related =>
prefetch_related
* version: 2.0 => master
* component: Database layer (models, ORM) => contrib.contenttypes
* stage: Unreviewed => Accepted


Comment:

This is similar to #26706 but for generic relations. The patch can
probably be heavily inspired by d30febb4e59b659e0d279c77f61f936c199a05b2.

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

Django

unread,
Jul 30, 2018, 12:43:31 PM7/30/18
to django-...@googlegroups.com
#29612: prefetch_related on GenericRelations
--------------------------------------+------------------------------------

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

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

Django

unread,
Jul 30, 2018, 2:52:20 PM7/30/18
to django-...@googlegroups.com
#29612: Add prefetch_related() cache invalidation for GenericRelations
--------------------------------------+------------------------------------

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

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

Django

unread,
Aug 7, 2018, 5:41:52 PM8/7/18
to django-...@googlegroups.com
#29612: Add prefetch_related() cache invalidation for GenericRelations
-------------------------------------+-------------------------------------
Reporter: obayemi | Owner: Tom
| Forbes
Type: Bug | Status: assigned
Component: | Version: master
contrib.contenttypes |

Severity: Normal | Resolution:
Keywords: prefetch_related | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tom Forbes):

* owner: nobody => Tom Forbes
* status: new => assigned


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

Django

unread,
Aug 7, 2018, 6:09:38 PM8/7/18
to django-...@googlegroups.com
#29612: Add prefetch_related() cache invalidation for GenericRelations
-------------------------------------+-------------------------------------
Reporter: obayemi | Owner: Tom
| Forbes
Type: Bug | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: prefetch_related | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tom Forbes):

* cc: Tom Forbes (added)


Comment:

'Heavily inspired' PR: https://github.com/django/django/pull/10277

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

Django

unread,
Aug 9, 2018, 7:05:07 PM8/9/18
to django-...@googlegroups.com
#29612: Add prefetch_related() cache invalidation for GenericRelations
-------------------------------------+-------------------------------------
Reporter: obayemi | Owner: Tom
| Forbes
Type: Bug | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: prefetch_related | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


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

Django

unread,
Aug 10, 2018, 3:11:09 AM8/10/18
to django-...@googlegroups.com
#29612: Add prefetch_related() cache invalidation for GenericRelations
-------------------------------------+-------------------------------------
Reporter: obayemi | Owner: Tom
| Forbes
Type: Bug | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: prefetch_related | 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 Carlton Gibson):

* stage: Accepted => Ready for checkin


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

Django

unread,
Aug 17, 2018, 3:21:40 PM8/17/18
to django-...@googlegroups.com
#29612: Add prefetch_related() cache invalidation for GenericRelations
-------------------------------------+-------------------------------------
Reporter: obayemi | Owner: Tom
| Forbes
Type: Bug | Status: closed
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution: fixed

Keywords: prefetch_related | 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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"c02d473781dc2e8699db8edd37cc77f7d43993fc" c02d4737]:
{{{
#!CommitTicketReference repository=""
revision="c02d473781dc2e8699db8edd37cc77f7d43993fc"
Fixed #29612 -- Added GenericRelation prefetch_related() cache
invalidation.
}}}

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

Reply all
Reply to author
Forward
0 new messages