1
0
mirror of https://github.com/django/django.git synced 2024-12-22 00:55:44 +00:00

Refs #35844 -- Fixed OtherModelFormTests.test_prefetch_related_queryset() test on Python 3.14+.

5a23994a3d
This commit is contained in:
Mariusz Felisiak 2024-12-20 08:43:14 +01:00 committed by Sarah Boyce
parent f05edb2b43
commit fcd9d08379

View File

@ -26,7 +26,7 @@ from django.test import SimpleTestCase, TestCase, ignore_warnings, skipUnlessDBF
from django.test.utils import isolate_apps from django.test.utils import isolate_apps
from django.utils.choices import BlankChoiceIterator from django.utils.choices import BlankChoiceIterator
from django.utils.deprecation import RemovedInDjango60Warning from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.version import PYPY from django.utils.version import PY314, PYPY
from .models import ( from .models import (
Article, Article,
@ -3048,10 +3048,11 @@ class OtherModelFormTests(TestCase):
return ", ".join(c.name for c in obj.colours.all()) return ", ".join(c.name for c in obj.colours.all())
field = ColorModelChoiceField(ColourfulItem.objects.prefetch_related("colours")) field = ColorModelChoiceField(ColourfulItem.objects.prefetch_related("colours"))
# CPython calls ModelChoiceField.__len__() when coercing to tuple. PyPy # CPython < 3.14 calls ModelChoiceField.__len__() when coercing to
# doesn't call __len__() and so .count() isn't called on the QuerySet. # tuple. PyPy and Python 3.14+ don't call __len__() and so .count()
# The following would trigger an extra query if prefetch were ignored. # isn't called on the QuerySet. The following would trigger an extra
with self.assertNumQueries(2 if PYPY else 3): # query if prefetch were ignored.
with self.assertNumQueries(2 if PYPY or PY314 else 3):
self.assertEqual( self.assertEqual(
tuple(field.choices), tuple(field.choices),
( (