mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
[Fix]: Error with partial=True and validate_<name>
The error occurs when serializer is set with partial=True and a field-level validation is defined on a field, for which there's no corresponding update value in .data
This commit is contained in:
parent
b74c5235c5
commit
c6be12f02b
|
@ -255,10 +255,13 @@ class BaseSerializer(WritableField):
|
|||
for field_name, field in self.fields.items():
|
||||
if field_name in self._errors:
|
||||
continue
|
||||
|
||||
source = field.source or field_name
|
||||
if self.partial and source not in attrs:
|
||||
continue
|
||||
try:
|
||||
validate_method = getattr(self, 'validate_%s' % field_name, None)
|
||||
if validate_method:
|
||||
source = field.source or field_name
|
||||
attrs = validate_method(attrs, source)
|
||||
except ValidationError as err:
|
||||
self._errors[field_name] = self._errors.get(field_name, []) + list(err.messages)
|
||||
|
|
Loading…
Reference in New Issue
Block a user