From 1ee5c2bd33e49b3f75bcaeeead9233f4fb8f6c05 Mon Sep 17 00:00:00 2001 From: Victor Skvortsov Date: Mon, 6 Oct 2025 15:08:57 +0500 Subject: [PATCH 1/2] Fix bool parsing for idle_duration --- src/dstack/_internal/core/models/profiles.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dstack/_internal/core/models/profiles.py b/src/dstack/_internal/core/models/profiles.py index 9097abed4..c7b585c6c 100644 --- a/src/dstack/_internal/core/models/profiles.py +++ b/src/dstack/_internal/core/models/profiles.py @@ -85,9 +85,13 @@ def parse_off_duration(v: Optional[Union[int, str, bool]]) -> Optional[Union[Lit return parse_duration(v) -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) From e33cb5c50310ffc30895c0c75afc078cc9ba3434 Mon Sep 17 00:00:00 2001 From: Victor Skvortsov Date: Mon, 6 Oct 2025 15:19:24 +0500 Subject: [PATCH 2/2] Forbid negative durations --- src/dstack/_internal/core/models/profiles.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dstack/_internal/core/models/profiles.py b/src/dstack/_internal/core/models/profiles.py index c7b585c6c..286b07492 100644 --- a/src/dstack/_internal/core/models/profiles.py +++ b/src/dstack/_internal/core/models/profiles.py @@ -80,13 +80,16 @@ 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, bool]]) -> Optional[int]: - # Differs from `parse_off_duration`` to accept negative durations as `off` + # 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