Ticket #15790: 15790_only_broken_for_proxy_models.2.diff

File 15790_only_broken_for_proxy_models.2.diff, 2.7 KB (added by Michał Modzelewski, 14 years ago)

Updated patch for trunk

  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index c29673e..57dbfa4 100644
    a b class Query(object):  
    549549        columns = set()
    550550        orig_opts = self.model._meta
    551551        seen = {}
    552         must_include = {self.model: set([orig_opts.pk])}
     552        if orig_opts.proxy:
     553            must_include = {orig_opts.proxy_for_model: set([orig_opts.pk])}
     554        else:
     555            must_include = {self.model: set([orig_opts.pk])}
    553556        for field_name in field_names:
    554557            parts = field_name.split(LOOKUP_SEP)
    555558            cur_model = self.model
  • tests/regressiontests/defer_regress/models.py

    diff --git a/tests/regressiontests/defer_regress/models.py b/tests/regressiontests/defer_regress/models.py
    index 8db8c29..4e4ab0a 100644
    a b class Leaf(models.Model):  
    3434class ResolveThis(models.Model):
    3535    num = models.FloatField()
    3636    name = models.CharField(max_length=16)
     37
     38class Proxy(Item):
     39    class Meta:
     40        proxy = True
  • tests/regressiontests/defer_regress/tests.py

    diff --git a/tests/regressiontests/defer_regress/tests.py b/tests/regressiontests/defer_regress/tests.py
    index 6f1b023..820aec8 100644
    a b from django.db import connection  
    77from django.db.models.loading import cache
    88from django.test import TestCase
    99
    10 from models import ResolveThis, Item, RelatedItem, Child, Leaf
     10from models import ResolveThis, Item, RelatedItem, Child, Leaf, Proxy
    1111
    1212
    1313class DeferRegressionTest(TestCase):
    class DeferRegressionTest(TestCase):  
    111111                Child,
    112112                Item,
    113113                Leaf,
     114                Proxy,
    114115                RelatedItem,
    115116                ResolveThis,
    116117            ]
    class DeferRegressionTest(TestCase):  
    139140                "Leaf_Deferred_name_value",
    140141                "Leaf_Deferred_second_child_value",
    141142                "Leaf_Deferred_value",
     143                "Proxy",
    142144                "RelatedItem",
    143145                "RelatedItem_Deferred_",
    144146                "RelatedItem_Deferred_item_id",
    class DeferRegressionTest(TestCase):  
    146148            ]
    147149        )
    148150
     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
    149157    def test_resolve_columns(self):
    150158        rt = ResolveThis.objects.create(num=5.0, name='Foobar')
    151159        qs = ResolveThis.objects.defer('num')
Back to Top