mirror of
https://github.com/django/django.git
synced 2025-10-29 08:36:09 +00:00
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.
This commit is contained in:
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user