Open NdubisiOnuora opened 5 years ago
Shouldn't you do this instead?:
class PlayerSerializer(Serializer):
name = fields.CharField()
class GameSerializer(Serializer):
name = fields.CharField()
country_of_origin = fields.CharField(required=False)
players = PlayersSerializer(required=False, many=True)
@shosca: I can't modify the definition of GameSerializer
, since another service expects it to be in that format. I'm piggybacking on that service, which does 99% of what I want. 😄
Even though
EnforceValidationFieldMixin
(https://github.com/dealertrack/django-rest-framework-braces/blob/master/drf_braces/serializers/enforce_validation_serializer.py#L10) is added to the MRO of the Serializer and all nested Serializers, theSerializer's.run_validation
method still does not run theEnforceValidationFieldMixin.run_validation
method or those of any subclasses ofEnforceValidationFieldMixin
that might overriderun_validation
.The current problem that I'm trying to solve is to ensure that I can drop errors for invalid data sent to any of the nested
Serializers
. One example is one in which the nestedSerializer
expects a dictionary but a list is sent to it instead.Example:
I expect that the
GameSerializer
be valid and the incorrect data in thePlayersSerializer
be dropped especially sinceself.parent.must_validate_fields
is set to an empty list inDropInvalidFieldsMixin.run_validation
.