Ticket #15790: 15790_only_broken_for_proxy_models.diff

File 15790_only_broken_for_proxy_models.diff, 2.6 KB (added by michal.modzelewski@…, 14 years ago)

Patch for this bug, with regression tests

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

     
    544544        columns = set()
    545545        orig_opts = self.model._meta
    546546        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])}
    548551        for field_name in field_names:
    549552            parts = field_name.split(LOOKUP_SEP)
    550553            cur_model = self.model
  • tests/regressiontests/defer_regress/tests.py

     
    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):
     
    111111                Child,
    112112                Item,
    113113                Leaf,
     114                Proxy,
    114115                RelatedItem,
    115116                ResolveThis,
    116117            ]
     
    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",
     
    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')
  • tests/regressiontests/defer_regress/models.py

     
    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
Back to Top