Merge pull request #2196 from tomchristie/tomchristie-improve-update-nested-validation

Improve checks for nested creates and updates.
This commit is contained in:
Kevin Brown 2014-12-03 17:57:47 -05:00
commit 66bce38b59

View File

@ -633,8 +633,8 @@ class ModelSerializer(Serializer):
# If we don't do this explicitly they'd likely get a confusing # If we don't do this explicitly they'd likely get a confusing
# error at the point of calling `Model.objects.create()`. # error at the point of calling `Model.objects.create()`.
assert not any( assert not any(
isinstance(field, BaseSerializer) and not field.read_only isinstance(field, BaseSerializer) and (key in validated_attrs)
for field in self.fields.values() for key, field in self.fields.items()
), ( ), (
'The `.create()` method does not suport nested writable fields ' 'The `.create()` method does not suport nested writable fields '
'by default. Write an explicit `.create()` method for serializer ' 'by default. Write an explicit `.create()` method for serializer '
@ -681,8 +681,8 @@ class ModelSerializer(Serializer):
def update(self, instance, validated_attrs): def update(self, instance, validated_attrs):
assert not any( assert not any(
isinstance(field, BaseSerializer) and not field.read_only isinstance(field, BaseSerializer) and (key in validated_attrs)
for field in self.fields.values() for key, field in self.fields.items()
), ( ), (
'The `.update()` method does not suport nested writable fields ' 'The `.update()` method does not suport nested writable fields '
'by default. Write an explicit `.update()` method for serializer ' 'by default. Write an explicit `.update()` method for serializer '