Ticket #15790: 15790_only_broken_for_proxy_models.diff
File 15790_only_broken_for_proxy_models.diff, 2.6 KB (added by , 14 years ago) |
---|
-
django/db/models/sql/query.py
544 544 columns = set() 545 545 orig_opts = self.model._meta 546 546 seen = {} 547 must_include = {self.model: set([orig_opts.pk])} 547 if orig_opts.proxy: 548 must_include = {orig_opts.proxy_for_model: set([orig_opts.pk])} 549 else: 550 must_include = {self.model: set([orig_opts.pk])} 548 551 for field_name in field_names: 549 552 parts = field_name.split(LOOKUP_SEP) 550 553 cur_model = self.model -
tests/regressiontests/defer_regress/tests.py
7 7 from django.db.models.loading import cache 8 8 from django.test import TestCase 9 9 10 from models import ResolveThis, Item, RelatedItem, Child, Leaf 10 from models import ResolveThis, Item, RelatedItem, Child, Leaf, Proxy 11 11 12 12 13 13 class DeferRegressionTest(TestCase): … … 111 111 Child, 112 112 Item, 113 113 Leaf, 114 Proxy, 114 115 RelatedItem, 115 116 ResolveThis, 116 117 ] … … 139 140 "Leaf_Deferred_name_value", 140 141 "Leaf_Deferred_second_child_value", 141 142 "Leaf_Deferred_value", 143 "Proxy", 142 144 "RelatedItem", 143 145 "RelatedItem_Deferred_", 144 146 "RelatedItem_Deferred_item_id", … … 146 148 ] 147 149 ) 148 150 151 # Regression for #15790 - only() broken for proxy models 152 proxy = Proxy.objects.create(name="proxy", value=42) 153 deferredproxy = Proxy.objects.only('other_value').get(pk=proxy.pk) 154 self.assertEqual(deferredproxy.name, proxy.name) 155 self.assertEqual(deferredproxy.value, proxy.value) 156 149 157 def test_resolve_columns(self): 150 158 rt = ResolveThis.objects.create(num=5.0, name='Foobar') 151 159 qs = ResolveThis.objects.defer('num') -
tests/regressiontests/defer_regress/models.py
34 34 class ResolveThis(models.Model): 35 35 num = models.FloatField() 36 36 name = models.CharField(max_length=16) 37 38 class Proxy(Item): 39 class Meta: 40 proxy = True