Skip to content

Commit f490d85

Browse files
authored
Fix idle duration: off and forbid negative durations (#3151)
* Fix bool parsing for idle_duration * Forbid negative durations
1 parent f9ef6cb commit f490d85

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,21 @@ 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

88-
def parse_idle_duration(v: Optional[Union[int, str]]) -> Optional[int]:
89-
if v == "off" or v == -1:
91+
def parse_idle_duration(v: Optional[Union[int, str, bool]]) -> Optional[int]:
92+
# Differs from `parse_off_duration` to accept negative durations as `off`
93+
# for backward compatibility.
94+
if v == "off" or v is False or v == -1:
9095
return -1
96+
if v is True:
97+
return None
9198
return parse_duration(v)
9299

93100

0 commit comments

Comments
 (0)