Fix nullable source='*'
fields
#6659
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3451, #5635, and #6609.
Description
When a field like
CustomField(source='*', allow_null=True)
is attempting to validate a null value, theField.validate_empty_values()
method returns(True, None)
. This indicates that further validation should be skipped. However,set_value
breaks, because the emptysource_attrs
indicates that a dictionary should be provided, but the value returned fromvalidate_empty_values
isNone
.This an unusual edge case, but I'd argue it's valid. Although the given value may be null,
source='*'
indicates that the field is validating the whole object, not just the given value. If we decide not validating is the correct behavior, thenvalidate_empty_values
should at least return an empty dict.Other considerations
I'm not entirely sure what the behavior should be when
CustomField(required=False)
orSerializer(partial=True)
.