Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[soc2009/multidb] Fixed #12402 -- `QuerySet.defer` now interacts prop…

…erly with `SQLCompiler` subclasses that implement `resolve_columns`.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11911 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit df2746b16cbf4f198927eaa3e3eb89e65f44d053 1 parent e95bc7b
Justin Bronn authored December 19, 2009
7  django/db/models/sql/compiler.py
@@ -627,6 +627,13 @@ def results_iter(self):
627 627
                             fields = self.query.select_fields + self.query.related_select_fields
628 628
                         else:
629 629
                             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]]
630 637
                     row = self.resolve_columns(row, fields)
631 638
 
632 639
                 if self.query.aggregate_select:
4  tests/regressiontests/defer_regress/models.py
@@ -31,6 +31,10 @@ class Leaf(models.Model):
31 31
     def __unicode__(self):
32 32
         return self.name
33 33
 
  34
+class ResolveThis(models.Model):
  35
+    num = models.FloatField()
  36
+    name = models.CharField(max_length=16)
  37
+
34 38
 __test__ = {"regression_tests": """
35 39
 Deferred fields should really be deferred and not accidentally use the field's
36 40
 default value just because they aren't passed to __init__.
9  tests/regressiontests/defer_regress/tests.py
... ...
@@ -0,0 +1,9 @@
  1
+from django.test import TestCase
  2
+from models import ResolveThis
  3
+
  4
+class 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)

0 notes on commit df2746b

Please sign in to comment.
Something went wrong with that request. Please try again.