-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
respecting ordered sequence while partial update is fixed #9902
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
1544faf
4fdb19c
9caec6e
88ea74c
0186c25
069c9fb
e1c8863
1206cc4
3bb0f16
12159c9
1457bbc
b0066ab
acf688b
733c207
471ce01
8afbbb2
5d20b80
b990481
dd44e4d
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 |
|---|---|---|
|
|
@@ -19,3 +19,5 @@ coverage.* | |
| !.github | ||
| !.gitignore | ||
| !.pre-commit-config.yaml | ||
|
|
||
| .idea | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1680,18 +1680,36 @@ def __init__(self, **kwargs): | |
| self.validators.append(MinLengthValidator(self.min_length, message=message)) | ||
|
|
||
| def get_value(self, dictionary): | ||
| if self.field_name not in dictionary: | ||
| if getattr(self.root, 'partial', False): | ||
| return empty | ||
| # We override the default field access in order to support | ||
| # lists in HTML forms. | ||
| if html.is_html_input(dictionary): | ||
| val = dictionary.getlist(self.field_name, []) | ||
| if len(val) > 0: | ||
| # Support QueryDict lists in HTML input. | ||
| # First, try to get the value using the plain field name with getlist. | ||
| # This handles standard HTML form list submissions like: | ||
| # <select multiple name="field"><option value="a">... | ||
| try: | ||
| # Call getlist with a single argument to support duck-typed MultiDicts | ||
| # that do not accept a default parameter. | ||
| val = dictionary.getlist(self.field_name) | ||
| except (TypeError, KeyError): | ||
| # Fall back to treating the value as not provided. | ||
| val = [] | ||
| if val: | ||
| # Support QueryDict lists and other list-like results in HTML input. | ||
| return val | ||
| # For partial updates, avoid calling parse_html_list unless indexed keys are present. | ||
| # This reduces unnecessary parsing overhead for omitted list fields. | ||
|
Comment on lines
+1699
to
+1700
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. This one is good |
||
| if getattr(self.root, 'partial', False): | ||
| # Quick check: are there any keys matching field_name[*]? | ||
|
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. Redundant |
||
| prefix = self.field_name + '[' | ||
| if not any(key.startswith(prefix) for key in dictionary): | ||
| return empty | ||
browniebroke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Parse indexed keys (e.g., field[0], field[1]) | ||
| # This handles form submissions with explicit indices | ||
|
Comment on lines
+1706
to
+1707
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. Redundant with parse_html_list docstring |
||
| return html.parse_html_list(dictionary, prefix=self.field_name, default=empty) | ||
|
|
||
| # Non-HTML input: standard dictionary access | ||
| if self.field_name not in dictionary and getattr(self.root, 'partial', False): | ||
| return empty | ||
| return dictionary.get(self.field_name, empty) | ||
|
|
||
| def to_internal_value(self, data): | ||
|
|
||
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.
That kind of explain why it was changed from
dictionary.getlist(self.field_name, [])and exception handling was added, however this sems out of scope of what we're trying to achieve here. Let's keep the call how it was unless you can come up with a concrete example justifying this