Skip to content

Commit e9ebed5

Browse files
auvipyCopilot
andauthored
Update rest_framework/fields.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent dfe6628 commit e9ebed5

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

rest_framework/fields.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,9 +1769,13 @@ def to_internal_value(self, data):
17691769
Dicts of native values <- Dicts of primitive datatypes.
17701770
"""
17711771
if html.is_html_input(data):
1772-
data = html.parse_html_dict(data, default={}) or {
1773-
k: v for k, v in data.items()
1774-
}
1772+
# Coerce HTML form inputs (e.g. QueryDict/MultiValueDict) to a plain dict.
1773+
# Use `.dict()` when available to preserve existing behaviour of taking
1774+
# the first value for each key, otherwise fall back to `dict()`.
1775+
if hasattr(data, 'dict'):
1776+
data = data.dict()
1777+
else:
1778+
data = dict(data)
17751779
if not isinstance(data, dict):
17761780
self.fail('not_a_dict', input_type=type(data).__name__)
17771781
if not self.allow_empty and len(data) == 0:

0 commit comments

Comments
 (0)