#19420: prefetch_related does not cache results when the model is inherited
-------------------------------------+-------------------------------------
Reporter: idanzalz@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Keywords: prefetch_related
Severity: Normal | inheritence
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19420>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.