Skip to content

Commit fcd9d08

Browse files
felixxmsarahboyce
authored andcommitted
Refs #35844 -- Fixed OtherModelFormTests.test_prefetch_related_queryset() test on Python 3.14+.
python/cpython@5a23994
1 parent f05edb2 commit fcd9d08

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tests/model_forms/tests.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from django.test.utils import isolate_apps
2727
from django.utils.choices import BlankChoiceIterator
2828
from django.utils.deprecation import RemovedInDjango60Warning
29-
from django.utils.version import PYPY
29+
from django.utils.version import PY314, PYPY
3030

3131
from .models import (
3232
Article,
@@ -3048,10 +3048,11 @@ def label_from_instance(self, obj):
30483048
return ", ".join(c.name for c in obj.colours.all())
30493049

30503050
field = ColorModelChoiceField(ColourfulItem.objects.prefetch_related("colours"))
3051-
# CPython calls ModelChoiceField.__len__() when coercing to tuple. PyPy
3052-
# doesn't call __len__() and so .count() isn't called on the QuerySet.
3053-
# The following would trigger an extra query if prefetch were ignored.
3054-
with self.assertNumQueries(2 if PYPY else 3):
3051+
# CPython < 3.14 calls ModelChoiceField.__len__() when coercing to
3052+
# tuple. PyPy and Python 3.14+ don't call __len__() and so .count()
3053+
# isn't called on the QuerySet. The following would trigger an extra
3054+
# query if prefetch were ignored.
3055+
with self.assertNumQueries(2 if PYPY or PY314 else 3):
30553056
self.assertEqual(
30563057
tuple(field.choices),
30573058
(

0 commit comments

Comments
 (0)