Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validators.NumberRange doesn't handle NaN #505

Closed
jon-brenner opened this issue Jul 30, 2019 · 1 comment · Fixed by #548
Closed

validators.NumberRange doesn't handle NaN #505

jon-brenner opened this issue Jul 30, 2019 · 1 comment · Fixed by #548
Labels
bug Unexpected behavior

Comments

@jon-brenner
Copy link

jon-brenner commented Jul 30, 2019

Validating a DecimalField with a NumberRange validator throws a decimal.InvalidOperation exception when the value of the field is NaN. I would expect validation to fail instead

File "/usr/local/lib/python3.6/dist-packages/wtforms/form.py", line 310, in validate
  return super(Form, self).validate(extra)
File "/usr/local/lib/python3.6/dist-packages/wtforms/form.py", line 152, in validate
  if not field.validate(self, extra):
File "/usr/local/lib/python3.6/dist-packages/wtforms/fields/core.py", line 206, in validate
  stop_validation = self._run_validation_chain(form, chain)
File "/usr/local/lib/python3.6/dist-packages/wtforms/fields/core.py", line 226, in _run_validation_chain
  validator(form, self)
File "/usr/local/lib/python3.6/dist-packages/wtforms/validators.py", line 134, in __call__
  if data is None or (self.min is not None and data < self.min) or 
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
@azmeuk
Copy link
Contributor

azmeuk commented Apr 17, 2020

I could reproduce this with both master and 2.2-maintenance.

>>> import wtforms
>>> from tests.common import DummyPostData
>>> class F(wtforms.Form):
...      a = wtforms.DecimalField(validators=[wtforms.validators.NumberRange(min=0, max=1)])
>>> F(DummyPostData({"a": "NaN"})).validate()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/azmeuk/dev/wtforms/wtforms/form.py", line 310, in validate
    return super(Form, self).validate(extra)
  File "/home/azmeuk/dev/wtforms/wtforms/form.py", line 152, in validate
    if not field.validate(self, extra):
  File "/home/azmeuk/dev/wtforms/wtforms/fields/core.py", line 206, in validate
    stop_validation = self._run_validation_chain(form, chain)
  File "/home/azmeuk/dev/wtforms/wtforms/fields/core.py", line 226, in _run_validation_chain
    validator(form, self)  
  File "/home/azmeuk/dev/wtforms/wtforms/validators.py", line 134, in __call__   
    if data is None or (self.min is not None and data < self.min) or 
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
[<class 'decimal.InvalidOperation'>]

azmeuk added a commit to azmeuk/wtforms that referenced this issue Apr 17, 2020
azmeuk added a commit to azmeuk/wtforms that referenced this issue Apr 17, 2020
azmeuk added a commit to azmeuk/wtforms that referenced this issue Apr 17, 2020
azmeuk added a commit to azmeuk/wtforms that referenced this issue Apr 18, 2020
@azmeuk azmeuk added the bug Unexpected behavior label Apr 19, 2020
azmeuk added a commit to azmeuk/wtforms that referenced this issue Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behavior
Development

Successfully merging a pull request may close this issue.

2 participants