File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ def get_flat_serializer_fields(
4444 for composite fields by returning 2 fields: one for the errors linked to
4545 the parent field and another one for errors linked to the child field.
4646 """
47- if not field :
47+ if not field or getattr ( field , "read_only" , False ) :
4848 return []
4949
5050 field = force_instance (field )
Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ class CustomSerializer(serializers.Serializer):
3838 field4 = NestedSerializer (many = True )
3939
4040
41+ class CustomSerializerWithNestedReadOnly (serializers .Serializer ):
42+ field1 = serializers .CharField ()
43+ field2 = serializers .ListField (child = serializers .IntegerField ())
44+ field3 = NestedSerializer (read_only = True )
45+ field4 = NestedSerializer (read_only = True , many = True )
46+
47+
4148def test_get_flat_serializer_fields ():
4249 fields = get_flat_serializer_fields (CustomSerializer (many = True ))
4350 expected_fields = {
@@ -59,6 +66,19 @@ def test_get_flat_serializer_fields():
5966 assert {field .name for field in fields } == expected_fields
6067
6168
69+ def test_get_flat_serializer_fields_with_nested_read_only ():
70+ """Check case when NestedSerializer is read-only with non read-only fields."""
71+ fields = get_flat_serializer_fields (CustomSerializerWithNestedReadOnly (many = True ))
72+ expected_fields = {
73+ "non_field_errors" ,
74+ "INDEX.non_field_errors" ,
75+ "INDEX.field1" ,
76+ "INDEX.field2" ,
77+ "INDEX.field2.INDEX" ,
78+ }
79+ assert {field .name for field in fields } == expected_fields
80+
81+
6282@pytest .fixture
6383def char_field ():
6484 return InputDataField (
You can’t perform that action at this time.
0 commit comments