2π
It makes no sense to run validate when of of the fields is invalid. Django will first validate the individual fields, and then construct a dictionary that contains the validated data and thus run the .validate(β¦)
method with that validated data.
But since the data of (at least) one of the fields is invalid, thus thus means that we can not construct such dictionary if valid data, and therefore the precondition of the .validate(β¦)
method no longer holds. In order to fix this, first these fields should be available.
For example your serializer might have a boolean field. If a value tralse
is for example passed to that field, and the field requires to be true
or false
, then what value should be passed for that field? A random boolean, the string tralse
?
Another field validator can simply require that the field is part of the request. This thus means that if that field validator fails, there is simply no value for that field. So the only sensical thing to do might be to omit it from the validated_data
dictionary, but the validate
method takes as precondition that all required fields are in the validated_data
dictionary. It thus again makes no sense to run validate
on that data.