Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed a problem when computing deferred fields on multiple related mo…

…dels.

Fixed #10710, as this fixes the second bug reported there.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10384 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2b1934ff3c3f80f58cc35bdcc03ae1b0ea6eb17e 1 parent 0a89a57
Malcolm Tredinnick authored April 04, 2009
7  django/db/models/sql/query.py
@@ -574,12 +574,13 @@ def deferred_to_data(self, target, callback):
574 574
         if not field_names:
575 575
             return
576 576
         columns = set()
577  
-        cur_model = self.model
578  
-        opts = cur_model._meta
  577
+        orig_opts = self.model._meta
579 578
         seen = {}
580  
-        must_include = {cur_model: set([opts.pk])}
  579
+        must_include = {self.model: set([orig_opts.pk])}
581 580
         for field_name in field_names:
582 581
             parts = field_name.split(LOOKUP_SEP)
  582
+            cur_model = self.model
  583
+            opts = orig_opts
583 584
             for name in parts[:-1]:
584 585
                 old_model = cur_model
585 586
                 source = opts.get_field_by_name(name)[0]
3  tests/regressiontests/defer_regress/models.py
@@ -24,6 +24,7 @@ class Child(models.Model):
24 24
 class Leaf(models.Model):
25 25
     name = models.CharField(max_length=10)
26 26
     child = models.ForeignKey(Child)
  27
+    second_child = models.ForeignKey(Child, related_name="other", null=True)
27 28
     value = models.IntegerField(default=42)
28 29
 
29 30
     def __unicode__(self):
@@ -87,6 +88,8 @@ def __unicode__(self):
87 88
 >>> obj = Leaf.objects.only("name", "child").select_related()[0]
88 89
 >>> obj.child.name
89 90
 u'c1'
  91
+>>> Leaf.objects.select_related().only("child__name", "second_child__name")
  92
+[<Leaf_Deferred_name_value: l1>]
90 93
 
91 94
 """
92 95
 }

0 notes on commit 2b1934f

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