#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

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?

Change History (1)

comment:1 Changed 15 months ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

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