From d9e701879612312391c0dca5c158b79a1dabcf18 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Wed, 31 May 2023 18:23:51 -0400 Subject: [PATCH] Refs #34570 -- Added extra tests for QuerySet.only() noops. --- tests/defer_regress/tests.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/defer_regress/tests.py b/tests/defer_regress/tests.py index fc2d87e12b..5b8a9367da 100644 --- a/tests/defer_regress/tests.py +++ b/tests/defer_regress/tests.py @@ -277,6 +277,28 @@ class DeferRegressionTest(TestCase): with self.assertNumQueries(1): self.assertEqual(Request.objects.defer("items").get(), request) + def test_only_many_to_many_ignored(self): + location = Location.objects.create() + request = Request.objects.create(location=location) + with self.assertNumQueries(1): + self.assertEqual(Request.objects.only("items").get(), request) + + def test_defer_reverse_many_to_many_ignored(self): + location = Location.objects.create() + request = Request.objects.create(location=location) + item = Item.objects.create(value=1) + request.items.add(item) + with self.assertNumQueries(1): + self.assertEqual(Item.objects.defer("request").get(), item) + + def test_only_reverse_many_to_many_ignored(self): + location = Location.objects.create() + request = Request.objects.create(location=location) + item = Item.objects.create(value=1) + request.items.add(item) + with self.assertNumQueries(1): + self.assertEqual(Item.objects.only("request").get(), item) + class DeferDeletionSignalsTests(TestCase): senders = [Item, Proxy]