Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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 jbronn authored
7 django/db/models/sql/compiler.py
View
@@ -627,6 +627,13 @@ def results_iter(self):
fields = self.query.select_fields + self.query.related_select_fields
else:
fields = self.query.model._meta.fields
+ # If the field was deferred, exclude it from being passed
+ # into `resolve_columns` because it wasn't selected.
+ only_load = self.deferred_to_columns()
+ if only_load:
+ db_table = self.query.model._meta.db_table
+ fields = [f for f in fields if db_table in only_load and
+ f.column in only_load[db_table]]
row = self.resolve_columns(row, fields)
if self.query.aggregate_select:
4 tests/regressiontests/defer_regress/models.py
View
@@ -31,6 +31,10 @@ class Leaf(models.Model):
def __unicode__(self):
return self.name
+class ResolveThis(models.Model):
+ num = models.FloatField()
+ name = models.CharField(max_length=16)
+
__test__ = {"regression_tests": """
Deferred fields should really be deferred and not accidentally use the field's
default value just because they aren't passed to __init__.
9 tests/regressiontests/defer_regress/tests.py
View
@@ -0,0 +1,9 @@
+from django.test import TestCase
+from models import ResolveThis
+
+class DeferRegressionTest(TestCase):
+ def test_resolve_columns(self):
+ rt = ResolveThis.objects.create(num=5.0, name='Foobar')
+ qs = ResolveThis.objects.defer('num')
+ self.assertEqual(1, qs.count())
+ self.assertEqual('Foobar', qs[0].name)
Please sign in to comment.
Something went wrong with that request. Please try again.