Opened 11 years ago
Closed 11 years ago
#22286 closed Uncategorized (worksforme)
TypedChoiceField rejects valid input with coerce=float
Reported by: | 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 |
Description
django.VERSION # >> (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) tcf.to_python('0.0') # >> 0.0 tcf.to_python('0.5') # >> 0.5 tcf.to_python('0') # 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?
Note:
See TracTickets
for help on using tickets.
The logic around to_python and TypedChoiceField was changed in a0f3eecc in response to #21397. The behaviour you describe is no longer present.