def run_validation(self, data=[]):
"""
We override the default `run_validation`, because the validation
performed by validators and the `.validate()` method should
be coerced into an error dictionary with a 'non_fields_error' key.
"""
(is_empty_value, data) = self.validate_empty_values(data)
if is_empty_value:
return data
try:
value = self.to_internal_value(data)
self.run_validators(value)
value = self.validate(value)
assert value is not None, '.validate() should return the validated data' # noqa
except (ValidationError, DjangoValidationError) as exc:
# TODO: Must be 'recipient' instead of 'to' in v2
raise ValidationError(
detail={
'to': data['to'],
'errors': get_validation_error_detail(exc)})
return value
评论列表
文章目录