summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-05-24 14:03:07 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-06-03 17:46:59 +0200
commit2bf4c5b9eaaf0a36cb0fb6c060625a5fb2fcf6c9 (patch)
treea6b0d7b15498790c89ac7ec00c727f2d6ff2917d /tests
parent37e5cc6d89b4653f05a1a00af2eb2187c907c935 (diff)
[5.2.x] Fixed #36416 -- Made QuerySet.in_bulk() account for composite pks in id_list.
Backport of 26313bc21932d0d3af278ab387549d63b1f64575 from main.
Diffstat (limited to 'tests')
-rw-r--r--tests/composite_pk/tests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/composite_pk/tests.py b/tests/composite_pk/tests.py
index 1a28a585fa..2245a472e4 100644
--- a/tests/composite_pk/tests.py
+++ b/tests/composite_pk/tests.py
@@ -147,6 +147,22 @@ class CompositePKTests(TestCase):
result = Comment.objects.in_bulk([self.comment.pk])
self.assertEqual(result, {self.comment.pk: self.comment})
+ @unittest.mock.patch.object(
+ type(connection.features), "max_query_params", new_callable=lambda: 10
+ )
+ def test_in_bulk_batching(self, mocked_max_query_params):
+ Comment.objects.all().delete()
+ num_requiring_batching = (connection.features.max_query_params // 2) + 1
+ comments = [
+ Comment(id=i, tenant=self.tenant, user=self.user)
+ for i in range(1, num_requiring_batching + 1)
+ ]
+ Comment.objects.bulk_create(comments)
+ id_list = list(Comment.objects.values_list("pk", flat=True))
+ with self.assertNumQueries(2):
+ comment_dict = Comment.objects.in_bulk(id_list=id_list)
+ self.assertQuerySetEqual(comment_dict, id_list)
+
def test_iterator(self):
"""
Test the .iterator() method of composite_pk models.