﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29612	Add prefetch_related() cache invalidation for GenericRelations	obayemi	Tom Forbes	"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 []>
}}}"	Bug	closed	contrib.contenttypes	dev	Normal	fixed	prefetch_related	Tom Forbes	Ready for checkin	1	0	0	0	0	0
