summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-09-15 21:11:14 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2012-09-16 22:58:40 +0300
commitf399a804c9436a5d3ef9e2b73c337904af2c753d (patch)
tree5baac5556a041f3b40da1d397412ff9ba8eae78d /django/db/models/sql
parent935a8635c2fe5b702c18027818ef4cceda4d83cd (diff)
Fixed #17485 regression -- only + select_related interaction
When doing deeper than one level select_related() + only queries(), the code introduced in b6c356b7bb97f3d6d4831b31e67868313bbbc090 errored incorrectly. Thanks to mrmachine for report & test case.
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/compiler.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 28d2404858..f06d6b11a4 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -609,8 +609,12 @@ class SQLCompiler(object):
restricted = False
for f, model in opts.get_fields_with_model():
+ # The get_fields_with_model() returns None for fields that live
+ # in the field's local model. So, for those fields we want to use
+ # the f.model - that is the field's local model.
+ field_model = model or f.model
if not select_related_descend(f, restricted, requested,
- only_load.get(model or self.query.model)):
+ only_load.get(field_model)):
continue
# The "avoid" set is aliases we want to avoid just for this
# particular branch of the recursion. They aren't permanently