﻿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
19420	prefetch_related does not cache results when the model is inherited	idanzalz@…	nobody	"given the following models:
{{{
class ParentBase(models.Model): pass

class Parent(models.Model): pass

class ParentWithBase(ParentBase): pass

class Child(models.Model):
    parent = models.ForeignKey('Parent')
    parent_with_base = models.ForeignKey('ParentWithBase')
}}}

When I try to select a child model and prefetch the parents, the parent with the base performs another query which I am trying to avoid.
So my test code is:
{{{
# Create the child and parent objects
Child.objects.create(parent = Parent.objects.create(), parent_with_base = ParentWithBase.objects.create())
# Select the child and prefetch the parents
child = Child.objects.prefetch_related('parent','parent_with_base').all()[0]
with self.assertNumQueries(0):
    child.parent # This works just fine - no queries are emitted
with self.assertNumQueries(0):
    child.parent_with_base # TEST FAILS HERE - since one query is emitted
}}}"	Bug	closed	Database layer (models, ORM)	1.4	Normal	fixed	prefetch_related inheritence	antonbaklanov@…	Unreviewed	0	0	0	0	0	0
