Code

Opened 7 years ago

Closed 7 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@…> 7 years ago.
3482.diff (936 bytes) - added by Jeff Bauer <jbauer@…> 7 years ago.
replaces 4490.diff patch

Download all attachments as: .zip

Change History (6)

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

comment:1 Changed 7 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 7 years ago by Jeff Bauer <jbauer@…>

replaces 4490.diff patch

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

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

comment:3 Changed 7 years ago by jacob

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

comment:4 Changed 7 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).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.