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 do not raise IndexError when it catches a ValueError #445

Closed
azmeuk opened this issue Aug 30, 2018 · 0 comments · Fixed by #551
Closed

Validators do not raise IndexError when it catches a ValueError #445

azmeuk opened this issue Aug 30, 2018 · 0 comments · Fixed by #551
Labels
bug Unexpected behavior

Comments

@azmeuk
Copy link
Member

azmeuk commented Aug 30, 2018

Hi. When a validator accidentally raises a ZeroDivisionError, the is correctly raised, but when a validator accidentally raises a ValueError, an IndexError is raised instead. This makes the debugging a bit more difficult.

Here is a script to reproduce the problem:

import wtforms
import werkzeug


def division_error_validator(form, field): raise ZeroDivisionError
class DivisionErrorForm(wtforms.Form):
    foo = wtforms.StringField(validators=[division_error_validator])

def value_error_validator(form, field): raise ValueError
class ValueErrorForm(wtforms.Form):
    foo = wtforms.StringField(validators=[value_error_validator])


try:
    DivisionErrorForm(werkzeug.ImmutableMultiDict({"bar": "baz"})).validate()
except ZeroDivisionError:
    print("ZeroDivisionError OK")
except Exception as exc:
    print("ZeroDivisionError KO - found %s" % type(exc))

try:
    ValueErrorForm(werkzeug.ImmutableMultiDict({"bar": "baz"})).validate()
except ValueError:
    print("ValueError OK")
except Exception as exc:
    print("ValueError KO - found %s" % type(exc))

# prints
# ZeroDivisionError OK
# ValueError KO - found <type 'exceptions.IndexError'>
@azmeuk azmeuk changed the title Validators do not catch ValueErrors Validators do not raise IndexError when it catches a ValueErrors Aug 30, 2018
@azmeuk azmeuk changed the title Validators do not raise IndexError when it catches a ValueErrors Validators do not raise IndexError when it catches a ValueError Aug 30, 2018
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 18, 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.

1 participant