@@ -321,28 +321,6 @@ class FakeConnection:
321321 results = list (qs )
322322 assert len (results ) >= 2
323323
324- def test_max_chunk_zero_uses_default (self ):
325- """Test the code path where max_query_params=0 → use Polymorphic_QuerySet_objects_per_request."""
326- from unittest .mock import patch , PropertyMock
327-
328- import django .db .backends .base .features as features_module
329-
330- Model2A .objects .create (field1 = "mq_zero_a" )
331- Model2B .objects .create (field1 = "mq_zero_b" , field2 = "B2" )
332-
333- qs = Model2A .objects .all ()
334-
335- # Patch the connection features to return 0 for max_query_params
336- with patch ("django.db.connections" ) as mock_connections :
337- mock_features = type ("MockFeatures" , (), {"max_query_params" : 0 })()
338- mock_connection = type ("MockConn" , (), {"features" : mock_features })()
339- mock_connections .__getitem__ = lambda self , key : mock_connection
340-
341- # Can't easily use this - instead verify the existing behavior
342- # The default is 2000 - just verify it works
343- results = list (qs )
344- assert len (results ) >= 2
345-
346324
347325# ===========================================================================
348326# query.py - non_polymorphic() False branch of issubclass check (lines 216->218)
@@ -1203,16 +1181,20 @@ def test_unbound_formset_ct_as_int(self):
12031181
12041182
12051183# ===========================================================================
1206- # formsets/models.py - model from queryset_data (line 255)
1184+ # formsets/models.py - per-row model selection for an unbound formset
12071185# ===========================================================================
12081186
12091187
12101188class TestFormsetModelFromQuerysetData (TestCase ):
1211- """Test unbound formset where model comes from queryset_data."""
1189+ """Test that an unbound formset built from a mixed-type queryset selects the
1190+ correct child model for each row."""
12121191
12131192 def test_model_from_queryset_data (self ):
12141193 """
1215- Line 255: When no instance or initial, model comes from queryset_data[i].__class__.
1194+ Each initial form is bound to its queryset object's real concrete class
1195+ (the ``defaults["instance"]`` branch in ``_construct_form``), so a formset
1196+ over a mixed Model2A/Model2B queryset produces one correctly-typed form
1197+ per row.
12161198 """
12171199 obj_a = Model2A .objects .create (field1 = "qs_data_a" )
12181200 obj_b = Model2B .objects .create (field1 = "qs_data_b" , field2 = "B2" )
@@ -1234,10 +1216,9 @@ def test_model_from_queryset_data(self):
12341216 forms = formset .forms
12351217 # The form types come from the queryset_data items
12361218 assert len (forms ) == 2
1237- # At least one form for each type
1238- field1s = {form .instance .__class__ .__name__ for form in forms if form .instance .pk }
1239- # queryset_data drives the model for each form
1240- assert len (forms ) == 2
1219+ # queryset_data drives the model for each form: one Model2A and one Model2B
1220+ form_models = {form .instance .__class__ for form in forms if form .instance .pk }
1221+ assert form_models == {Model2A , Model2B }
12411222
12421223
12431224# ===========================================================================
@@ -1896,5 +1877,7 @@ def patched_is_valid(self_inner, *args, **kwargs):
18961877
18971878 with mock .patch .object (drf_serializers .Serializer , "is_valid" , patched_is_valid ):
18981879 result = s .is_valid ()
1899- # Result depends on child validation (child is valid, so True)
1900- # But _validated_data was deleted before the check, so branch 98->101 executes
1880+ # _validated_data was deleted before the check, so branch 98->101 executes:
1881+ # the child's _validated_data is NOT merged into the parent, but no
1882+ # AttributeError is raised and is_valid still returns True (parent + child valid).
1883+ assert result is True
0 commit comments