Fix dotted-source field checking on serializer write

The code was previously checking the validated data for the field's
attribute name, however, the data contain the first source attr.
This commit is contained in:
Ryan P Kilby 2019-07-05 18:03:26 -07:00
parent 8f44c5c630
commit aa7941470a

View File

@ -819,10 +819,10 @@ def raise_errors_on_nested_writes(method_name, serializer, validated_data):
# ... # ...
# address = serializer.CharField('profile.address') # address = serializer.CharField('profile.address')
assert not any( assert not any(
'.' in field.source and len(field.source_attrs) > 1 and
(key in validated_data) and (field.source_attrs[0] in validated_data) and
isinstance(validated_data[key], (list, dict)) isinstance(validated_data[field.source_attrs[0]], (list, dict))
for key, field in serializer.fields.items() for field in serializer._writable_fields
), ( ), (
'The `.{method_name}()` method does not support writable dotted-source ' 'The `.{method_name}()` method does not support writable dotted-source '
'fields by default.\nWrite an explicit `.{method_name}()` method for ' 'fields by default.\nWrite an explicit `.{method_name}()` method for '