Fix DictField partial HTML omission handling#9906
Open
Sebastianhayashi wants to merge 1 commit intoencode:mainfrom
Open
Fix DictField partial HTML omission handling#9906Sebastianhayashi wants to merge 1 commit intoencode:mainfrom
Sebastianhayashi wants to merge 1 commit intoencode:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Django REST framework’s DictField behavior for HTML/multipart inputs during partial updates so that an omitted dict field is treated as “missing” (sentinel empty) rather than an empty dict, preventing it from incorrectly appearing in validated_data.
Changes:
- Updated
DictField.get_value()to returnemptywhen HTML parsing yields no keys during partial updates. - Added a regression test covering the partial-update omission case for HTML input.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
rest_framework/fields.py |
Treats empty parsed HTML dict input as omitted (empty) when partial=True. |
tests/test_fields.py |
Adds regression test ensuring omitted HTML dict fields do not appear in validated_data on partial updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix
DictFieldhandling for HTML form input on partial updates.When the field is omitted in multipart/HTML input,
DictField.get_value()currently returns{}and the serializer incorrectly treats the field as provided. This change returnsemptyfor partial updates when parsed HTML dict input is empty, so omitted fields stay omitted.Reproduction
Changes
rest_framework/fields.pyDictField.get_value(), for HTML input:parse_html_dictself.root.partialis true, returnemptytests/test_fields.pytest_partial_update_does_not_include_missing_html_dict_fieldValidation
Result:
3 passedRelated to #6234.