mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Add possible solution for field validation error
This commit is contained in:
parent
dc1c57d595
commit
2250ab6418
|
@ -227,13 +227,14 @@ class BaseSerializer(Field):
|
||||||
Run `validate_<fieldname>()` and `validate()` methods on the serializer
|
Run `validate_<fieldname>()` and `validate()` methods on the serializer
|
||||||
"""
|
"""
|
||||||
for field_name, field in self.fields.items():
|
for field_name, field in self.fields.items():
|
||||||
try:
|
if field_name not in self._errors:
|
||||||
validate_method = getattr(self, 'validate_%s' % field_name, None)
|
try:
|
||||||
if validate_method:
|
validate_method = getattr(self, 'validate_%s' % field_name, None)
|
||||||
source = field.source or field_name
|
if validate_method:
|
||||||
attrs = validate_method(attrs, source)
|
source = field.source or field_name
|
||||||
except ValidationError as err:
|
attrs = validate_method(attrs, source)
|
||||||
self._errors[field_name] = self._errors.get(field_name, []) + list(err.messages)
|
except ValidationError as err:
|
||||||
|
self._errors[field_name] = self._errors.get(field_name, []) + list(err.messages)
|
||||||
|
|
||||||
# If there are already errors, we don't run .validate() because
|
# If there are already errors, we don't run .validate() because
|
||||||
# field-validation failed and thus `attrs` may not be complete.
|
# field-validation failed and thus `attrs` may not be complete.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user