Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweaks to writable nested serializers #739

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions rest_framework/serializers.py
Expand Up @@ -129,8 +129,8 @@ class Meta(object):
_dict_class = SortedDictWithMetadata

def __init__(self, instance=None, data=None, files=None,
context=None, partial=False, many=None, source=None):
super(BaseSerializer, self).__init__(source=source)
context=None, partial=False, many=None, **kwargs):
super(BaseSerializer, self).__init__(**kwargs)
self.opts = self._options_class(self.Meta)
self.parent = None
self.root = None
Expand Down Expand Up @@ -358,9 +358,13 @@ def field_from_native(self, data, files, field_name, into):
try:
value = data[field_name]
except KeyError:
if self.required:
raise ValidationError(self.error_messages['required'])
return
if self.default is not None and not self.partial:
# Note: partial updates shouldn't set defaults
value = copy.deepcopy(self.default)
else:
if self.required:
raise ValidationError(self.error_messages['required'])
return

# Set the serializer object if it exists
obj = getattr(self.parent.object, field_name) if self.parent.object else None
Expand Down