Ticket #17485: 17485-only-select_related.diff

File 17485-only-select_related.diff, 2.3 KB (added by Tai Lee, 12 years ago)

failing test case

  • tests/regressiontests/defer_regress/models.py

    diff --git a/tests/regressiontests/defer_regress/models.py b/tests/regressiontests/defer_regress/models.py
    index d02adcc..444649a 100644
    a b class SimpleItem(models.Model):  
    5252class Feature(models.Model):
    5353    item = models.ForeignKey(SimpleItem)
    5454
     55class SpecialFeature(models.Model):
     56    feature = models.ForeignKey(Feature)
     57
    5558class ItemAndSimpleItem(models.Model):
    5659    item = models.ForeignKey(Item)
    5760    simple = models.ForeignKey(SimpleItem)
  • tests/regressiontests/defer_regress/tests.py

    diff --git a/tests/regressiontests/defer_regress/tests.py b/tests/regressiontests/defer_regress/tests.py
    index 53bb59f..adc6966 100644
    a b from django.db.models.loading import cache  
    99from django.test import TestCase
    1010
    1111from .models import (ResolveThis, Item, RelatedItem, Child, Leaf, Proxy,
    12     SimpleItem, Feature, ItemAndSimpleItem)
     12    SimpleItem, Feature, ItemAndSimpleItem, SpecialFeature)
    1313
    1414
    1515class DeferRegressionTest(TestCase):
    class DeferRegressionTest(TestCase):  
    115115                RelatedItem,
    116116                ResolveThis,
    117117                SimpleItem,
     118                SpecialFeature,
    118119            ]
    119120        )
    120121
    class DeferRegressionTest(TestCase):  
    152153                "RelatedItem_Deferred_item_id",
    153154                "ResolveThis",
    154155                "SimpleItem",
     156                "SpecialFeature",
    155157            ]
    156158        )
    157159
    class DeferRegressionTest(TestCase):  
    197199        self.assertEqual(obj.item, item2)
    198200        self.assertEqual(obj.item_id, item2.id)
    199201
     202    def test_only_with_select_related(self):
     203        item = SimpleItem.objects.create(name='first', value=47)
     204        feature = Feature.objects.create(item=item)
     205        special_feature = SpecialFeature.objects.create(feature=feature)
     206
     207        qs = Feature.objects.only('item__name').select_related('item__name')
     208        self.assertEqual(len(qs), 1)
     209
     210        qs = SpecialFeature.objects.only('feature__item__name').select_related('feature__item__name')
     211        self.assertEqual(len(qs), 1)
     212
    200213    def test_deferred_class_factory(self):
    201214        from django.db.models.query_utils import deferred_class_factory
    202215        new_class = deferred_class_factory(Item,
Back to Top