summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-06-06 00:25:15 -0400
committerNatalia <124304+nessita@users.noreply.github.com>2025-08-13 15:30:34 -0300
commita4e27c0c6bcc37ad7d7f6098e5d44edbbcca2c42 (patch)
tree02b9cd9462396d26c75ca029a72d82f27786c544 /tests
parent4926591343756d9fdd5d57680e021364ff71288f (diff)
[5.2.x] Refs #34378, #36143, #36416 -- Fixed isolation of LookupTests.test_in_bulk_preserve_ordering_with_batch_size().
`max_query_params` is a property, so it must be patched on the class. Backport of a68e8565cdd4fc3f8b738fc516095dab142b9d65 from main.
Diffstat (limited to 'tests')
-rw-r--r--tests/lookup/tests.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index e19fbca521..7e4d267f4c 100644
--- a/tests/lookup/tests.py
+++ b/tests/lookup/tests.py
@@ -2,7 +2,7 @@ import collections.abc
from datetime import datetime
from math import ceil
from operator import attrgetter
-from unittest import skipUnless
+from unittest import mock, skipUnless
from django.core.exceptions import FieldError
from django.db import connection, models
@@ -261,20 +261,15 @@ class LookupTests(TestCase):
@skipUnlessDBFeature("can_distinct_on_fields")
def test_in_bulk_preserve_ordering_with_batch_size(self):
- old_max_query_params = connection.features.max_query_params
- connection.features.max_query_params = 1
- try:
- articles = (
- Article.objects.order_by("author_id", "-pub_date")
- .distinct("author_id")
- .in_bulk([self.au1.id, self.au2.id], field_name="author_id")
- )
+ qs = Article.objects.order_by("author_id", "-pub_date").distinct("author_id")
+ with (
+ mock.patch.object(connection.features.__class__, "max_query_params", 1),
+ self.assertNumQueries(2),
+ ):
self.assertEqual(
- articles,
+ qs.in_bulk([self.au1.id, self.au2.id], field_name="author_id"),
{self.au1.id: self.a4, self.au2.id: self.a5},
)
- finally:
- connection.features.max_query_params = old_max_query_params
@skipUnlessDBFeature("can_distinct_on_fields")
def test_in_bulk_distinct_field(self):