Opened 3 years ago

Closed 3 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: master
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 3 years ago.
prefetch_related_multi_table_bug.2.diff (3.0 KB) - added by milosu 3 years ago.
shorter and still working patch, which does not lead to deadlock while resolving pkey

Download all attachments as: .zip

Change History (6)

Changed 3 years ago by milosu

comment:1 Changed 3 years ago by milosu

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.4 to master

comment:2 Changed 3 years ago by milosu

  • Has patch set

Changed 3 years ago by milosu

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

comment:3 Changed 3 years ago by jezdez

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 3 years ago by Luke Plant <L.Plant.98@…>

  • Resolution set to fixed
  • Status changed from new to closed

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