diff --git a/src/dstack/_internal/core/models/profiles.py b/src/dstack/_internal/core/models/profiles.py index 9097abed4..286b07492 100644 --- a/src/dstack/_internal/core/models/profiles.py +++ b/src/dstack/_internal/core/models/profiles.py @@ -80,14 +80,21 @@ def parse_stop_duration( def parse_off_duration(v: Optional[Union[int, str, bool]]) -> Optional[Union[Literal["off"], int]]: if v == "off" or v is False: return "off" - if v is True: + if v is True or v is None: return None - return parse_duration(v) + duration = parse_duration(v) + if duration < 0: + raise ValueError("Duration cannot be negative") + return duration -def parse_idle_duration(v: Optional[Union[int, str]]) -> Optional[int]: - if v == "off" or v == -1: +def parse_idle_duration(v: Optional[Union[int, str, bool]]) -> Optional[int]: + # Differs from `parse_off_duration` to accept negative durations as `off` + # for backward compatibility. + if v == "off" or v is False or v == -1: return -1 + if v is True: + return None return parse_duration(v)