mirror of
https://github.com/django/django.git
synced 2025-08-25 19:29:14 +00:00
[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.
This commit is contained in:
parent
4926591343
commit
a4e27c0c6b
@ -2,7 +2,7 @@ import collections.abc
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from unittest import skipUnless
|
from unittest import mock, skipUnless
|
||||||
|
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from django.db import connection, models
|
from django.db import connection, models
|
||||||
@ -261,20 +261,15 @@ class LookupTests(TestCase):
|
|||||||
|
|
||||||
@skipUnlessDBFeature("can_distinct_on_fields")
|
@skipUnlessDBFeature("can_distinct_on_fields")
|
||||||
def test_in_bulk_preserve_ordering_with_batch_size(self):
|
def test_in_bulk_preserve_ordering_with_batch_size(self):
|
||||||
old_max_query_params = connection.features.max_query_params
|
qs = Article.objects.order_by("author_id", "-pub_date").distinct("author_id")
|
||||||
connection.features.max_query_params = 1
|
with (
|
||||||
try:
|
mock.patch.object(connection.features.__class__, "max_query_params", 1),
|
||||||
articles = (
|
self.assertNumQueries(2),
|
||||||
Article.objects.order_by("author_id", "-pub_date")
|
):
|
||||||
.distinct("author_id")
|
|
||||||
.in_bulk([self.au1.id, self.au2.id], field_name="author_id")
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
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},
|
{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")
|
@skipUnlessDBFeature("can_distinct_on_fields")
|
||||||
def test_in_bulk_distinct_field(self):
|
def test_in_bulk_distinct_field(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user