aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index 33db82ee..4210d058 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -262,10 +262,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)
@@ -403,7 +406,7 @@ class BaseSerializer(WritableField):
return
# Set the serializer object if it exists
- obj = getattr(self.parent.object, field_name) if self.parent.object else None
+ obj = get_component(self.parent.object, self.source or field_name) if self.parent.object else None
obj = obj.all() if is_simple_callable(getattr(obj, 'all', None)) else obj
if self.source == '*':
@@ -912,7 +915,7 @@ class ModelSerializer(Serializer):
def save_object(self, obj, **kwargs):
"""
- Save the deserialized object and return it.
+ Save the deserialized object.
"""
if getattr(obj, '_nested_forward_relations', None):
# Nested relationships need to be saved before we can save the