summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-06-26 18:08:42 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2012-06-26 18:08:42 +0300
commitb6c356b7bb97f3d6d4831b31e67868313bbbc090 (patch)
tree1cd4c587080703c5b86b13349858509ce145ca4c /django/db/models/sql/query.py
parent531878302735e6a2b36d82b584947bbf8eae8111 (diff)
Fixed #17485 -- Made defer work with select_related
This commit tackles a couple of issues. First, in certain cases there were some mixups if field.attname or field.name should be deferred. Field.attname is now always used. Another issue tackled is a case where field is both deferred by .only(), and selected by select_related. This case is now an error. A lot of thanks to koniiiik (Michal Petrucha) for the patch, and to Andrei Antoukh for review.
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 7f331bfe7f..8fbba3dbc9 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1845,9 +1845,15 @@ class Query(object):
If no fields are marked for deferral, returns an empty dictionary.
"""
- collection = {}
- self.deferred_to_data(collection, self.get_loaded_field_names_cb)
- return collection
+ # We cache this because we call this function multiple times
+ # (compiler.fill_related_selections, query.iterator)
+ try:
+ return self._loaded_field_names_cache
+ except AttributeError:
+ collection = {}
+ self.deferred_to_data(collection, self.get_loaded_field_names_cb)
+ self._loaded_field_names_cache = collection
+ return collection
def get_loaded_field_names_cb(self, target, model, fields):
"""