Ticket #11890: 16409-defer-only-annotate-r16510.diff
File 16409-defer-only-annotate-r16510.diff, 2.7 KB (added by , 13 years ago) |
---|
-
django/db/models/sql/compiler.py
169 169 if isinstance(col, (list, tuple)): 170 170 alias, column = col 171 171 table = self.query.alias_map[alias][TABLE_NAME] 172 if table in only_load and col not in only_load[table]:172 if table in only_load and column not in only_load[table]: 173 173 continue 174 174 r = '%s.%s' % (qn(alias), qn(column)) 175 175 if with_aliases: -
django/db/models/query.py
231 231 fields = self.model._meta.fields 232 232 pk_idx = self.model._meta.pk_index() 233 233 234 index_start = len(extra_select)235 aggregate_start = index_start + len(self.model._meta.fields)236 237 234 load_fields = [] 238 235 # If only/defer clauses have been specified, 239 236 # build the list of fields that are to be loaded. … … 253 250 # Therefore, we need to load all fields from this model 254 251 load_fields.append(field.name) 255 252 253 index_start = len(extra_select) 254 aggregate_start = index_start + len(load_fields or self.model._meta.fields) 255 256 256 skip = None 257 257 if load_fields and not fill_cache: 258 258 # Some fields have been deferred, so we have to initialise -
tests/regressiontests/defer_regress/tests.py
4 4 from django.contrib.contenttypes.models import ContentType 5 5 from django.contrib.sessions.backends.db import SessionStore 6 6 from django.db import connection 7 from django.db.models import Count 7 8 from django.db.models.loading import cache 8 9 from django.test import TestCase 9 10 … … 148 149 ] 149 150 ) 150 151 152 # Regression for #16409 - make sure defer() and only() work with annotate() 153 self.assertIsInstance(list(Item.objects.annotate(Count('relateditem')).defer('name')), list) 154 self.assertIsInstance(list(Item.objects.annotate(Count('relateditem')).only('name')), list) 155 151 156 def test_only_and_defer_usage_on_proxy_models(self): 152 157 # Regression for #15790 - only() broken for proxy models 153 158 proxy = Proxy.objects.create(name="proxy", value=42)