Skip to content

Commit

Permalink
per #2420, prevent crash if increment is set to an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemccabe committed Nov 13, 2023
1 parent 6d63b0a commit 1a0dc1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/tests/pytests/util/time_looping/test_time_looping.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ def test_time_generator_error_check_beg_end(metplus_config, prefix):
# _INCREMENT is less than 60 seconds
config.set('config', f'{prefix}_INCREMENT', '10S')
assert next(tl.time_generator(config)) is None

# _INCREMENT is empty string
config.set('config', f'{prefix}_INCREMENT', '')
assert next(tl.time_generator(config)) is not None

config.set('config', f'{prefix}_INCREMENT', '1d')

# _END time comes before _BEG time
Expand Down
9 changes: 6 additions & 3 deletions metplus/util/time_looping.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ def time_generator(config):
# if list is not provided, use _BEG, _END, and _INCREMENT
start_string = config.getraw('config', f'{prefix}_BEG')
end_string = config.getraw('config', f'{prefix}_END', start_string)
time_interval = get_relativedelta(
config.getstr('config', f'{prefix}_INCREMENT', '60')
)

time_interval = config.getstr('config', f'{prefix}_INCREMENT', '60')
# if [INIT/VALID]_INCREMENT is an empty string, set it to prevent crash
if not time_interval:
time_interval = '60'
time_interval = get_relativedelta(time_interval)

start_dt = _get_current_dt(start_string,
time_format,
Expand Down

0 comments on commit 1a0dc1a

Please sign in to comment.