Use(bool) doesn't properly validate boolean strings.
EdEngle opened this issue · comments
Ed Engle commented
Use(bool)
will return True for strings that should be false.
t = Schema({"test_bool": Use(bool)})
t.validate({"test": "false"})
the code above will return {'test': True}
I would recommend using distutils.util.strtobool
to convert strings to booleans. This will convert things like "TRUE", "True", "true", "T", 1
to True and it will convert "FALSE", "False", "false", "F", "f", 0
to False.
Ed Engle commented
FYI to those wondering you can do this....
def convert_bool(input_bool):
return bool(strtobool(str(input_bool)))
t = Schema({"test_bool": Use(convert_bool)})
t.validate({"test": "false"})
And that will evaluate test to False correctly.