Ticket #15523: deffer_bug.diff
File deffer_bug.diff, 2.3 KB (added by , 14 years ago) |
---|
-
django/db/models/sql/compiler.py
156 156 if isinstance(col, (list, tuple)): 157 157 alias, column = col 158 158 table = self.query.alias_map[alias][TABLE_NAME] 159 if table in only_load and col not in only_load[table]:159 if table in only_load and column not in only_load[table]: 160 160 continue 161 161 r = '%s.%s' % (qn(alias), qn(column)) 162 162 if with_aliases: -
django/db/models/query.py
264 264 # Model wasn't explicitly listed in the only_load table 265 265 # Therefore, we need to load all fields from this model 266 266 load_fields.append(field.name) 267 # fix aggregate start based on the new number of fields 268 aggregate_start = index_start + len(load_fields) 267 269 268 270 skip = None 269 271 if load_fields and not fill_cache: -
tests/regressiontests/defer_regress/tests.py
1 1 from django.test import TestCase 2 from models import ResolveThis 2 from django.db.models import Count 3 from models import ResolveThis, Child, Leaf 3 4 4 5 class DeferRegressionTest(TestCase): 5 6 def test_resolve_columns(self): … … 7 8 qs = ResolveThis.objects.defer('num') 8 9 self.assertEqual(1, qs.count()) 9 10 self.assertEqual('Foobar', qs[0].name) 11 def test_annotations(self): 12 ch = Child.objects.create(name='first', value=10) 13 l = Leaf.objects.create(name='leaf', child = ch) 14 qset = Leaf.objects.all().annotate(max_cnt = Count('child')).only('id', 'name') 15 self.assertTrue(len(qset) == 1) 16 self.assertTrue(qset[0].name == u'leaf') 17 self.assertTrue(qset[0].id == 1) 18 self.assertTrue(qset[0].max_cnt == 1)