Refs #34570 -- Added extra tests for QuerySet.only() noops.

This commit is contained in:
Simon Charette 2023-05-31 18:23:51 -04:00 committed by Mariusz Felisiak
parent 4142739af1
commit d9e7018796
1 changed files with 22 additions and 0 deletions

View File

@ -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]