From a68e8565cdd4fc3f8b738fc516095dab142b9d65 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 6 Jun 2025 00:25:15 -0400 Subject: [PATCH] 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. --- tests/lookup/tests.py | 19 +++++++------------ 1 file 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):