From fa2e1e633ac2073906ed3f1f32107d02331107aa Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 2 Oct 2015 19:53:50 -0400 Subject: [PATCH] Refs #15844 -- Added tests for multi-table inheritance related object filtering efficiency. Fixed in 97774429aeb54df4c09895c07cd1b09e70201f7d. --- tests/model_inheritance_regress/tests.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/model_inheritance_regress/tests.py b/tests/model_inheritance_regress/tests.py index e04fb18e94..7dc73b6de5 100644 --- a/tests/model_inheritance_regress/tests.py +++ b/tests/model_inheritance_regress/tests.py @@ -493,3 +493,22 @@ class ModelInheritanceTest(TestCase): jane = Supplier.objects.order_by("name").select_related("restaurant")[0] self.assertEqual(jane.restaurant.name, "Craft") + + def test_related_filtering_query_efficiency_ticket_15844(self): + r = Restaurant.objects.create( + name="Guido's House of Pasta", + address='944 W. Fullerton', + serves_hot_dogs=True, + serves_pizza=False, + ) + s = Supplier.objects.create(restaurant=r) + with self.assertNumQueries(1): + self.assertQuerysetEqual( + Supplier.objects.filter(restaurant=r), + [s], lambda x: x, + ) + with self.assertNumQueries(1): + self.assertQuerysetEqual( + r.supplier_set.all(), + [s], lambda x: x, + )