inconsistent validation behavior for child serializers #7792
Unanswered
ozgurakcali
asked this question in
Question & Answer
Replies: 2 comments
-
A note, observed that this behavior only happens when sending a PATCH request, for POST and PUT validations are run by default for field_1 being required as well. If forwarding the "partial update" behavior to child serializers on PATCH requests is the desired behavior, than there doesn't seem to be a problem here. But I'm not sure if that would always be the desired behavior. |
Beta Was this translation helpful? Give feedback.
0 replies
-
If this is the desired behavior it should be mentioned this in the documentation |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Steps to reproduce
With the following serializers structure:
Expected behavior
Without explicitly calling is_valid method of child serializer from parent serializer, either do not run any validations on child serializer, or run all validations on child serializer.
Actual behavior
When is_valid method is run on parent serializer, if we do not run child serializer's is_valid method explicitly (in validate_children method for example), validations for field_1 being required are not checked, but validate method of ChildSerializer is called.
If we explicitly call is_valid method of ChildSerializer, all validations for ChildSerializer are run.
As they are defined now, serializer is actually invalid for both cases, but a validation error is raised for the second case, but not for the first case.
Beta Was this translation helpful? Give feedback.
All reactions