Skip to content

Commit 665cf39

Browse files
authored
Add support for clearing a dict field with form data
1 parent 3324ed6 commit 665cf39

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

rest_framework/fields.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,14 @@ def get_value(self, dictionary):
17541754
# We override the default field access in order to support
17551755
# dictionaries in HTML forms.
17561756
if html.is_html_input(dictionary):
1757-
return html.parse_html_dict(dictionary, prefix=self.field_name, default=empty)
1757+
result = html.parse_html_dict(dictionary, prefix=self.field_name, default=empty)
1758+
if result is not empty:
1759+
return result
1760+
# If the field name itself is present in the input,
1761+
# treat it as an explicit empty dict (e.g. clearing the field).
1762+
if self.field_name in dictionary:
1763+
return {}
1764+
return empty
17581765
return dictionary.get(self.field_name, empty)
17591766

17601767
def to_internal_value(self, data):

0 commit comments

Comments
 (0)