Ticket #15523: deffer_bug.diff

File deffer_bug.diff, 2.3 KB (added by milosu, 4 years ago)
  • django/db/models/sql/compiler.py

     
    156156                if isinstance(col, (list, tuple)):
    157157                    alias, column = col
    158158                    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]:
    160160                        continue
    161161                    r = '%s.%s' % (qn(alias), qn(column))
    162162                    if with_aliases:
  • django/db/models/query.py

     
    264264                    # Model wasn't explicitly listed in the only_load table
    265265                    # Therefore, we need to load all fields from this model
    266266                    load_fields.append(field.name)
     267            # fix aggregate start based on the new number of fields
     268            aggregate_start = index_start + len(load_fields)
    267269
    268270        skip = None
    269271        if load_fields and not fill_cache:
  • tests/regressiontests/defer_regress/tests.py

     
    11from django.test import TestCase
    2 from models import ResolveThis
     2from django.db.models import Count
     3from models import ResolveThis, Child, Leaf
    34
    45class DeferRegressionTest(TestCase):
    56    def test_resolve_columns(self):
     
    78        qs = ResolveThis.objects.defer('num')
    89        self.assertEqual(1, qs.count())
    910        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)
Back to Top