Opened 12 years ago

Closed 12 years ago

#18309 closed Bug (fixed)

Prefetch related does not work for fkey to multitable inherited model

Reported by: milosu Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using Django 1.4 with some latest prefetch related patches from trunk, the prefetch_related does not work for fkeys to models that are inherited from some other model.

Without the applied patch, the attached test case fails with:

======================================================================
ERROR: test_foreignkey (modeltests.prefetch_related.tests.MultiTableInheritanceT
est)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python26\Lib\site-packages\django_versions\trunk\tests\modeltests\pre
fetch_related\tests.py", line 344, in test_foreignkey
    reviews = [obj.book.title for obj in qs]
  File "C:\Python26\lib\site-packages\django_versions\trunk\django\db\models\fie
lds\related.py", line 379, in __get__
    raise self.field.rel.to.DoesNotExist
DoesNotExist

Attachments (2)

prefetch_related_multi_table_bug.diff (4.0 KB ) - added by milosu 12 years ago.
prefetch_related_multi_table_bug.2.diff (3.0 KB ) - added by milosu 12 years ago.
shorter and still working patch, which does not lead to deadlock while resolving pkey

Download all attachments as: .zip

Change History (6)

comment:1 by milosu, 12 years ago

Version: 1.4master

comment:2 by milosu, 12 years ago

Has patch: set

by milosu, 12 years ago

shorter and still working patch, which does not lead to deadlock while resolving pkey

comment:3 by Jannis Leidel, 12 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Luke Plant <L.Plant.98@…>, 12 years ago

Resolution: fixed
Status: newclosed

In [4fea46a030689d7ae774ee0217dbce28de5a1b29]:

Fixed #18309 - Prefetch related does not work for fkey to multitable inherited model

Thanks to milosu for the report, tests and initial patch.

Note: See TracTickets for help on using tickets.
Back to Top