Validator
Validator copied to clipboard
An integer expected, but the text can be a valid value.
Bug Description: This rule is valid? An integer expected, but the text can be a valid value.
Code Fragment:
valid = Validator({'session_id': 'abcd'}, {'session_id': 'required|integer|min:1'})
Validating 'aaa' as an integer is pretty confusing.
>>> validate({"d":'aaa'}, {"d":'integer|min:1'}, return_info=True)
(True, {'d': 'aaa'}, {})
I think the root issue is that the request is somehow converted to an integer, which has not much to do with the original string. In this example the error message indicates this conversion: 'aaa' -> 2730
>>> validate({"d":'aaa'}, {"d":'integer|max:1'}, return_info=True)
(False, {}, {'d': {'Max': 'Expected Maximum: 1, Got: 2730'}})