From 38a68a3956b8ac075e1b8750ca204d3674a4bf8c Mon Sep 17 00:00:00 2001 From: Jose Caballero Bejar Date: Tue, 27 Jan 2026 11:54:24 +0000 Subject: [PATCH 1/2] Check type of input options As the fields for the end of the downtimes are optional, always one of them will be left blank on the web form. StackStorm doesn't process them as an empty string, but as None. Therefore, we can not just try "strip()" on their values without checking first they are not a None one. --- lib/workflows/hypervisor_downtime.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/workflows/hypervisor_downtime.py b/lib/workflows/hypervisor_downtime.py index adee8df95..ee1ab2125 100644 --- a/lib/workflows/hypervisor_downtime.py +++ b/lib/workflows/hypervisor_downtime.py @@ -31,8 +31,10 @@ def get_number_of_hours(start_dt, end_time_str, duration): :raises ValueError: if the input string is invalid or contains negative values """ - end_time_str = end_time_str.strip() - duration = duration.strip() + if end_time_str is not None: + end_time_str = end_time_str.strip() + if duration is not None: + duration = duration.strip() if not end_time_str and not duration: raise ValueError("Input strings cannot be both empty at the same time") From 15d598e1aba1883d94d314591d0bce5c4883e413 Mon Sep 17 00:00:00 2001 From: David Fairbrother Date: Tue, 27 Jan 2026 12:02:59 +0000 Subject: [PATCH 2/2] TEST: add unit tests for handling "None" types correctly Adds unit tests to ensure that None types can be handled correctly before we try to perform string operations on them --- tests/lib/workflows/test_hypervisor_downtimes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/lib/workflows/test_hypervisor_downtimes.py b/tests/lib/workflows/test_hypervisor_downtimes.py index beb035fa0..6db0fdc57 100644 --- a/tests/lib/workflows/test_hypervisor_downtimes.py +++ b/tests/lib/workflows/test_hypervisor_downtimes.py @@ -150,6 +150,18 @@ def test_both_single_space_raise_exception(): get_number_of_hours(start_dt, " ", " ") +def test_none_types_handled_too(): + """Test that both parameters as None in either field does not raise a ValueError""" + start_dt = datetime.datetime.strptime("2024-01-01 10:00", "%Y-%m-%d %H:%M").replace( + tzinfo=pytz.utc + ) + result = get_number_of_hours(start_dt, "2024-01-01 11:00", None) + assert result == 1 + + result = get_number_of_hours(start_dt, None, "1h") + assert result == 1 + + def test_both_multiple_spaces_raise_exception(): """Test that both parameters as multiple spaces raise ValueError""" start_dt = datetime.datetime.strptime("2024-01-01 10:00", "%Y-%m-%d %H:%M").replace(