Ticket #12402: defer_resolve_columns_fix_v1.diff

File defer_resolve_columns_fix_v1.diff, 2.2 KB (added by jbronn, 9 years ago)
  • django/db/models/sql/compiler.py

     
    627627                            fields = self.query.select_fields + self.query.related_select_fields
    628628                        else:
    629629                            fields = self.query.model._meta.fields
     630                        # If the field was deferred, exclude it from being passed
     631                        # into `resolve_columns` because it wasn't selected.
     632                        only_load = self.deferred_to_columns()
     633                        if only_load:
     634                            db_table = self.query.model._meta.db_table
     635                            fields = [f for f in fields if db_table in only_load and
     636                                      f.column in only_load[db_table]]
    630637                    row = self.resolve_columns(row, fields)
    631638
    632639                if self.query.aggregate_select:
  • tests/regressiontests/defer_regress/tests.py

     
     1from django.test import TestCase
     2from models import ResolveThis
     3
     4class DeferRegressionTest(TestCase):
     5    def test_resolve_columns(self):
     6        rt = ResolveThis.objects.create(num=5.0, name='Foobar')
     7        qs = ResolveThis.objects.defer('num')
     8        self.assertEqual(1, qs.count())
     9        self.assertEqual('Foobar', qs[0].name)
  • tests/regressiontests/defer_regress/models.py

     
    3131    def __unicode__(self):
    3232        return self.name
    3333
     34class ResolveThis(models.Model):
     35    num = models.FloatField()
     36    name = models.CharField(max_length=16)
     37
    3438__test__ = {"regression_tests": """
    3539Deferred fields should really be deferred and not accidentally use the field's
    3640default value just because they aren't passed to __init__.
Back to Top