From 37643b5a8b3aefba4d9ccb28db03f1ba27c6f0fa Mon Sep 17 00:00:00 2001 From: Israel Date: Thu, 17 Aug 2023 07:55:42 -0300 Subject: [PATCH] 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 --- patroni/validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patroni/validator.py b/patroni/validator.py index a8ada1f5..326997b4 100644 --- a/patroni/validator.py +++ b/patroni/validator.py @@ -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)