-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Fix DictField partial HTML omission handling #9906
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2522,6 +2522,14 @@ def test_allow_empty_disallowed(self): | |||||||||||||||||||
|
|
||||||||||||||||||||
| assert exc_info.value.detail == ['This dictionary may not be empty.'] | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def test_partial_update_does_not_include_missing_html_dict_field(self): | ||||||||||||||||||||
| class TestSerializer(serializers.Serializer): | ||||||||||||||||||||
| field_name = serializers.DictField(required=False) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| serializer = TestSerializer(data=QueryDict(''), partial=True) | ||||||||||||||||||||
| assert serializer.is_valid() | ||||||||||||||||||||
| assert 'field_name' not in serializer.validated_data | ||||||||||||||||||||
|
Comment on lines
+2525
to
+2531
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to increate test coverage... This test passes on the main branch, but breaks here: def test_partial_update_can_clear_html_dict_field(self):
class TestSerializer(serializers.Serializer):
field_name = serializers.DictField(required=False)
serializer = TestSerializer(data=QueryDict('field_name='), partial=True)
assert serializer.is_valid()
assert 'field_name' in serializer.validated_data |
||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+2532
to
2533
|
||||||||||||||||||||
| def test_full_update_missing_required_html_dict_field_is_error(self): | |
| class TestSerializer(serializers.Serializer): | |
| field_name = serializers.DictField(required=True) | |
| serializer = TestSerializer(data=QueryDict(''), partial=False) | |
| assert not serializer.is_valid() | |
| assert 'field_name' in serializer.errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DictField.get_value()still returns an empty dict for omitted HTML/multipart input whenpartial=False. That means omitted DictFields can bypass the normalemptysentinel handling (e.g.,required=Truewon’t raise “required”, andrequired=Falsefields can incorrectly show up invalidated_dataas{}). Consider matchingSerializer.get_value()/ListField.get_value()behavior by returningemptywheneverparse_html_dict(...)is empty (e.g.,... or empty), not only on partial updates.