aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Huang2013-09-15 18:03:52 -0700
committerColin2013-10-15 17:05:10 -0700
commitc6be12f02b5e07e412c8c91b368566a85364b907 (patch)
tree36d431f1337b8f31232893a96bb550d0234d1f8b
parentb74c5235c509738c7afea0be0dd8283bb8339ebe (diff)
downloaddjango-rest-framework-c6be12f02b5e07e412c8c91b368566a85364b907.tar.bz2
[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
-rw-r--r--rest_framework/serializers.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index a63c7f6c..0b5ae042 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -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)