mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-07 23:23:18 +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():
|
for field_name, field in self.fields.items():
|
||||||
if field_name in self._errors:
|
if field_name in self._errors:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
source = field.source or field_name
|
||||||
|
if self.partial and source not in attrs:
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
validate_method = getattr(self, 'validate_%s' % field_name, None)
|
validate_method = getattr(self, 'validate_%s' % field_name, None)
|
||||||
if validate_method:
|
if validate_method:
|
||||||
source = field.source or field_name
|
|
||||||
attrs = validate_method(attrs, source)
|
attrs = validate_method(attrs, source)
|
||||||
except ValidationError as err:
|
except ValidationError as err:
|
||||||
self._errors[field_name] = self._errors.get(field_name, []) + list(err.messages)
|
self._errors[field_name] = self._errors.get(field_name, []) + list(err.messages)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user