From a4ac4963d1bcaac3b7326c65f191d3fa8341dc61 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 c99b3d32..ddfb2c07 100644 --- a/patroni/validator.py +++ b/patroni/validator.py @@ -799,7 +799,7 @@ class IntValidator(object): :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)