-
-
Notifications
You must be signed in to change notification settings - Fork 403
Closed
Labels
bugUnexpected behaviorUnexpected behavior
Description
Actual Behavior
>>> class DummyPostData(dict):
... def getlist(self, key):
... v = self[key]
... if not isinstance(v, (list, tuple)):
... v = [v]
... return v
...
>>> import wtforms
>>> class F(wtforms.Form):
... foo=wtforms.SelectMultipleField(choices=[('1', 'One'), ('2', 'Two')], coerce=int)
...
>>> post_data = DummyPostData(foo=["1", "2"])
>>> form = F(post_data)
>>> form.validate()
False
>>> form.errors
{'foo': ["'1', '2' are not valid choices for this field."]}Expected Behavior
The form should be valid when the post data is a valid option after coercing both post data and choices:
>>> class DummyPostData(dict):
... def getlist(self, key):
... v = self[key]
... if not isinstance(v, (list, tuple)):
... v = [v]
... return v
...
>>> import wtforms
>>> class F(wtforms.Form):
... foo=wtforms.SelectMultipleField(choices=[('1', 'One'), ('2', 'Two')], coerce=int)
...
>>> post_data = DummyPostData(foo=["1", "2"])
>>> form = F(post_data)
>>> form.validate()
TrueEnvironment
- Python version: 3.9
- wtforms version: 3.1.1
Metadata
Metadata
Assignees
Labels
bugUnexpected behaviorUnexpected behavior