* status: closed => new
* severity: => Normal
* resolution: fixed =>
* easy: => 0
* ui_ux: => 0
* type: => Uncategorized
Comment:
This is still happening for me in Django 3.1.13:
{{{
>>> from django.forms import MultipleChoiceField
>>> f = MultipleChoiceField(required=False, choices=[('1', '1'), ('2',
'2')])
>>> f.clean([''])
Traceback (most recent call last):
File "/Users/joshsmith/.pyenv/versions/3.9.4/lib/python3.9/code.py",
line 90, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
File "/Users/joshsmith/code/course-platform/.venv/lib/python3.9/site-
packages/django/forms/fields.py", line 150, in clean
self.validate(value)
File "/Users/joshsmith/code/course-platform/.venv/lib/python3.9/site-
packages/django/forms/fields.py", line 883, in validate
raise ValidationError(
django.core.exceptions.ValidationError: ['Select a valid choice. is not
one of the available choices.']
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/3482#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 1 => 0
* type: Uncategorized => Bug
* stage: Ready for checkin => Unreviewed
--
Ticket URL: <https://code.djangoproject.com/ticket/3482#comment:6>
* status: new => closed
* resolution: => wontfix
Comment:
So, it's hard to say about the dark-history here, as bootstrapping a very
old environment is somewhat fiddly these days but
[https://github.com/django/django/blob/d0ea01af2814e276c4a090e599d5fd11c6ce4bf8/django/forms/fields.py#L884-L890
the logic here] is virtually unchanged from the
[https://github.com/django/django/commit/6645d1fe48868814e4c73056b68be5c3861ed2d0
#diff-
19fae1b4e3786d4af8cdf8db08d18d687caeae43859b35c769deb96d3aacf05cR256-R260
earliest days of the MultipleChoiceField implementation]. It's certainly
unchanged as far back as Django 1.8. Without a serious case being made,
the backwards compatibility concerns preclude changing this now.
However, for me, this is expected behaviour: `''` is **not** a valid
choice. If I want filtering of empty values then I'm expecting to use a
widget to filter this in `value_from_datadict`, or else a field subclass,
if I want the behaviour there. The default implementation is doing the
right thing here rejecting the incorrect value.
--
Ticket URL: <https://code.djangoproject.com/ticket/3482#comment:7>