Opened 8 years ago

Closed 8 years ago

#3482 closed (fixed)

MultipleChoiceField validation against a list with a single null element

Reported by: Jeff Bauer <jbauer@…> Owned by: nobody
Component: Forms Version: master
Severity: Keywords: MultipleChoiceField
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

MultipleChoiceField fails validation when required=False against a list with a single null value (as opposed to when value itself is null)

>>> f = MultipleChoiceField(required=False, choices=[('1', '1'), ('2', '2')])
>>> f.clean([''])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "django/newforms/fields.py", line 386, in clean
    if val not in valid_values:
django.newforms.util.ValidationError: [u'Select a valid choice.  is not one of the available choices.']
>>> 

Attachments (2)

4490.diff (941 bytes) - added by Jeff Bauer <jbauer@…> 8 years ago.
3482.diff (936 bytes) - added by Jeff Bauer <jbauer@…> 8 years ago.
replaces 4490.diff patch

Download all attachments as: .zip

Change History (6)

Changed 8 years ago by Jeff Bauer <jbauer@…>

comment:1 Changed 8 years ago by adrian

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

In your example, shouldn't f.clean(['']) return [] rather than ['']?

Changed 8 years ago by Jeff Bauer <jbauer@…>

replaces 4490.diff patch

comment:2 Changed 8 years ago by Jeff Bauer <jbauer@…>

New patch. Clean now returns an empty list rather than the original value.

comment:3 Changed 8 years ago by jacob

  • Triage Stage changed from Design decision needed to Ready for checkin

comment:4 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

This has already been fixed at some point in the interim (and we're testing it).

Note: See TracTickets for help on using tickets.
Back to Top