SIGN IN SIGN UP

Fix DictField HTML input returning empty dict for missing fields (#9891)

* Fix DictField returning empty dict instead of empty for missing HTML input (#6234)

When using DictField with HTML form (multipart/form-data) input,
parse_html_dict always returned an empty MultiValueDict when no
matching keys were found. This made it impossible to distinguish
between an unspecified field and an empty input, causing issues
with required/default field handling.

This aligns parse_html_dict with parse_html_list by adding a
default parameter that is returned when no matching keys are found.

* Address review feedback: add regression test, improve assertions

- Add regression test for nested serializer with QueryDict to cover
  the serializers.py get_value change (test_nested_serializer_not_required_with_querydict)
- Use `assert serializer.is_valid(), serializer.errors` for better
  test output on failures
- Keep `default=data` in to_internal_value as `default={}` would
  discard already-parsed MultiValueDict keys from get_value

* Use empty dict as default in DictField.to_internal_value()

Change default from data to {} in parse_html_dict call within
DictField.to_internal_value(), falling back to a dict conversion
of the MultiValueDict when no dot-separated keys are found. This
is cleaner than using the input data as its own default.

* Add support for clearing a dict field with form data

* Update rest_framework/fields.py

* Update rest_framework/utils/html.py

---------
Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com>
Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
V
Varun Chawla committed
69d1cd7f1322060397b7f747d199e3926f5d297b
Parent: bbc62ac
Committed by GitHub <noreply@github.com> on 8/6/2026, 8:46:24 AM