Opened 3 years ago

Closed 3 years ago

#22286 closed Uncategorized (worksforme)

TypedChoiceField rejects valid input with coerce=float

Reported by: johnnybrown7@… Owned by: nobody
Component: Uncategorized Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


# >> (1, 5, 5, 'final', 0)
from django.forms.fields import TypedChoiceField
tcf = TypedChoiceField(choices=[(0.0, 'ugh'), (0.5, 'meh'), (1.0, 'yay')], coerce=float)

# >> 0.0

# >> 0.5

# raises ValidationError('Select a valid choice. 0 is not one of the available choices.')
# same thing happens with tc.to_python('1')

float('0') works just fine, and produces a value in the choices, so why does the validation fail?

Change History (1)

comment:1 Changed 3 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: worksforme
Status: newclosed

The logic around to_python and TypedChoiceField was changed in a0f3eecc in response to #21397. The behaviour you describe is no longer present.

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