Skip to content

Commit

Permalink
Merge pull request #2196 from tomchristie/tomchristie-improve-update-…
Browse files Browse the repository at this point in the history
…nested-validation

Improve checks for nested creates and updates.
  • Loading branch information
kevin-brown committed Dec 3, 2014
2 parents 5f2f54b + e1d98f7 commit 66bce38
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ def create(self, validated_attrs):
# If we don't do this explicitly they'd likely get a confusing
# error at the point of calling `Model.objects.create()`.
assert not any(
isinstance(field, BaseSerializer) and not field.read_only
for field in self.fields.values()
isinstance(field, BaseSerializer) and (key in validated_attrs)
for key, field in self.fields.items()
), (
'The `.create()` method does not suport nested writable fields '
'by default. Write an explicit `.create()` method for serializer '
Expand Down Expand Up @@ -681,8 +681,8 @@ def create(self, validated_attrs):

def update(self, instance, validated_attrs):
assert not any(
isinstance(field, BaseSerializer) and not field.read_only
for field in self.fields.values()
isinstance(field, BaseSerializer) and (key in validated_attrs)
for key, field in self.fields.items()
), (
'The `.update()` method does not suport nested writable fields '
'by default. Write an explicit `.update()` method for serializer '
Expand Down

0 comments on commit 66bce38

Please sign in to comment.