Add check to ensure that ListSerializer is used only with a serializer as its child #9452
Unanswered
sevdog
asked this question in
Ideas & Suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In #9386 it was asked to normalize the return value of
ListSerializer.to_representation
to better handle null values.By reading the docs it states that:
In my intendement the use-case of providing a "normal" field as child to
ListSerializer
is not taken into account. To handle such use case it already exists theListField
.I tried working on a PR to enforce this check and found out that there are some tests where a
ListSerializer
is istantiated with a field as child in the unittests:django-rest-framework/tests/test_serializer_lists.py
Lines 218 to 220 in 4d06626
django-rest-framework/tests/test_serializer_lists.py
Lines 340 to 351 in 4d06626
django-rest-framework/tests/schemas/test_coreapi.py
Line 68 in 4d06626
django-rest-framework/tests/test_metadata.py
Lines 79 to 83 in 4d06626
My point is: it is fine to let ListSerializer have any kind of child or it would be better to have it validating the type of its child?
Beta Was this translation helpful? Give feedback.
All reactions