Fix IntValidator regarding validation of value 0 (#2818)

Previous to this commit `IntValidator` would always consider the value `0` invalid, even if in the allowed range.

The problem was that `parse_int` was returning `0` in the following line:

```python
value = parse_int(value, self.base_unit) or ""
```

However the `or ""` was evaluating to an empty string.

As `parse_int` returns either an `int` if able to parse, or `None` otherwise, the `isinstance(value, int)` is enough to error out when not a valid `int`.

Closes #2817
This commit is contained in:
Israel
2023-09-18 12:59:54 +02:00
committed by Alexander Kukushkin
parent f659edd60f
commit 37643b5a8b
+1 -1
View File
@@ -793,7 +793,7 @@ class IntValidator(object):
:param value: value to be checked against the rules defined for this :class:`IntValidator` instance.
:returns: ``True`` if *value* is valid and within the expected range.
"""
value = parse_int(value, self.base_unit) or ""
value = parse_int(value, self.base_unit)
ret = isinstance(value, int)\
and (self.min is None or value >= self.min)\
and (self.max is None or value <= self.max)