summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorafenoum <anja1catus@gmail.com>2026-03-26 11:30:02 +0300
committerJacob Walls <jacobtylerwalls@gmail.com>2026-03-26 15:21:00 -0400
commit8b7ea2bcdd7297941ca6beb72d93b9568e187349 (patch)
tree524931260dec3d917809ab720fc229e9568102e7 /django
parentf6167b8bc881babd19b67c004e8f37954afc192e (diff)
Refs #36913 -- Maintained error message determinism in MultipleChoiceField.validate().
Used Django's OrderedSet datastructure instead of set() in MultipleChoiceField.validate() to prevent submission ordering from being discarded during validation. Thanks to Jacob Walls, JaeHyuck Sa, Jake Howard and Simon Charette for the reviews.
Diffstat (limited to 'django')
-rw-r--r--django/forms/fields.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 7f978aa03d..8aad2d48b8 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -40,6 +40,7 @@ from django.forms.widgets import (
)
from django.utils import formats
from django.utils.choices import normalize_choices
+from django.utils.datastructures import OrderedSet
from django.utils.dateparse import parse_datetime, parse_duration
from django.utils.duration import duration_string
from django.utils.ipv6 import MAX_IPV6_ADDRESS_LENGTH, clean_ipv6_address
@@ -965,8 +966,8 @@ class MultipleChoiceField(ChoiceField):
if self.required and not value:
raise ValidationError(self.error_messages["required"], code="required")
# Validate that each value in the value list is in self.choices.
- # Use set() to avoid redundant validation.
- for val in set(value):
+ # Avoid redundant validation, and keep elements ordered.
+ for val in OrderedSet(value):
if not self.valid_value(val):
raise ValidationError(
self.error_messages["invalid_choice"],