mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user