Validator icon indicating copy to clipboard operation
Validator copied to clipboard

An integer expected, but the text can be a valid value.

Open dzhaugasharov opened this issue 4 years ago • 2 comments

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'})

dzhaugasharov avatar May 17 '21 05:05 dzhaugasharov

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'}})

karolyjozsa avatar Jul 05 '22 00:07 karolyjozsa