Ticket #11890: 16409-defer-only-annotate-r16510.diff

File 16409-defer-only-annotate-r16510.diff, 2.7 KB (added by Tai Lee, 13 years ago)

Bogus test.

  • django/db/models/sql/compiler.py

     
    169169                if isinstance(col, (list, tuple)):
    170170                    alias, column = col
    171171                    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]:
    173173                        continue
    174174                    r = '%s.%s' % (qn(alias), qn(column))
    175175                    if with_aliases:
  • django/db/models/query.py

     
    231231            fields = self.model._meta.fields
    232232            pk_idx = self.model._meta.pk_index()
    233233
    234         index_start = len(extra_select)
    235         aggregate_start = index_start + len(self.model._meta.fields)
    236 
    237234        load_fields = []
    238235        # If only/defer clauses have been specified,
    239236        # build the list of fields that are to be loaded.
     
    253250                    # Therefore, we need to load all fields from this model
    254251                    load_fields.append(field.name)
    255252
     253        index_start = len(extra_select)
     254        aggregate_start = index_start + len(load_fields or self.model._meta.fields)
     255
    256256        skip = None
    257257        if load_fields and not fill_cache:
    258258            # Some fields have been deferred, so we have to initialise
  • tests/regressiontests/defer_regress/tests.py

     
    44from django.contrib.contenttypes.models import ContentType
    55from django.contrib.sessions.backends.db import SessionStore
    66from django.db import connection
     7from django.db.models import Count
    78from django.db.models.loading import cache
    89from django.test import TestCase
    910
     
    148149            ]
    149150        )
    150151
     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
    151156    def test_only_and_defer_usage_on_proxy_models(self):
    152157        # Regression for #15790 - only() broken for proxy models
    153158        proxy = Proxy.objects.create(name="proxy", value=42)
Back to Top