Skip to content

Cannot validate raw integer 0 with required IntegerField. #39

@m-martinez

Description

@m-martinez

I'm having issues validating a required IntegerField when the JSON value passed is 0:

import wtforms_json
wtforms_json.init()

from wtforms import Form, IntegerField
from wtforms.validators import InputRequired

class MyForm(Form):
    a = IntegerField(validators=[InputRequired()])

# Works with > 0
form = MyForm.from_json({'a': 5})
assert form.validate()

# Does not work with value 0
form = MyForm.from_json({'a': 0})
assert form.validate()

# Works with string '0'
form = MyForm.from_json({'a': '0'})
assert form.validate()

Using wtforms 2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions