Skip to content

Commit e33cb5c

Browse files
committed
Forbid negative durations
1 parent 1ee5c2b commit e33cb5c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/dstack/_internal/core/models/profiles.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ def parse_stop_duration(
8080
def parse_off_duration(v: Optional[Union[int, str, bool]]) -> Optional[Union[Literal["off"], int]]:
8181
if v == "off" or v is False:
8282
return "off"
83-
if v is True:
83+
if v is True or v is None:
8484
return None
85-
return parse_duration(v)
85+
duration = parse_duration(v)
86+
if duration < 0:
87+
raise ValueError("Duration cannot be negative")
88+
return duration
8689

8790

8891
def parse_idle_duration(v: Optional[Union[int, str, bool]]) -> Optional[int]:
89-
# Differs from `parse_off_duration`` to accept negative durations as `off`
92+
# Differs from `parse_off_duration` to accept negative durations as `off`
9093
# for backward compatibility.
9194
if v == "off" or v is False or v == -1:
9295
return -1

0 commit comments

Comments
 (0)