Skip to content

Commit 3ceddfd

Browse files
authored
Fix 500 server error when re-applying replica groups service (#3678)
Co-authored-by: Bihan Rana
1 parent 1568525 commit 3ceddfd

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def validate_scaling(cls, values):
989989
@root_validator()
990990
def validate_top_level_properties_with_replica_groups(cls, values):
991991
"""
992-
When replicas is a list of ReplicaGroup, forbid top-level scaling, commands, and resources
992+
When replicas is a list of ReplicaGroup, forbid top-level scaling and commands.
993993
"""
994994
replicas = values.get("replicas")
995995

@@ -1010,15 +1010,6 @@ def validate_top_level_properties_with_replica_groups(cls, values):
10101010
"Specify `commands` in each replica group instead."
10111011
)
10121012

1013-
resources = values.get("resources")
1014-
1015-
default_resources = ResourcesSpec()
1016-
if resources and resources.dict() != default_resources.dict():
1017-
raise ValueError(
1018-
"Top-level `resources` is not allowed when `replicas` is a list. "
1019-
"Specify `resources` in each replica group instead."
1020-
)
1021-
10221013
return values
10231014

10241015
@root_validator()

src/dstack/_internal/server/services/runs/spec.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ServiceConfiguration,
66
)
77
from dstack._internal.core.models.repos.virtual import DEFAULT_VIRTUAL_REPO_ID, VirtualRunRepoData
8+
from dstack._internal.core.models.resources import ResourcesSpec
89
from dstack._internal.core.models.runs import LEGACY_REPO_DIR, AnyRunConfiguration, RunSpec
910
from dstack._internal.core.models.volumes import InstanceMountPoint
1011
from dstack._internal.core.services import validate_dstack_resource_name
@@ -112,6 +113,16 @@ def validate_run_spec_and_set_defaults(
112113
raise ServerClientError(
113114
f"Probe timeout cannot be longer than {settings.MAX_PROBE_TIMEOUT}s"
114115
)
116+
if isinstance(run_spec.configuration.replicas, list):
117+
default_resources = ResourcesSpec()
118+
if (
119+
run_spec.configuration.resources
120+
and run_spec.configuration.resources.dict() != default_resources.dict()
121+
):
122+
raise ServerClientError(
123+
"Top-level `resources` is not allowed when `replicas` is a list. "
124+
"Specify `resources` in each replica group instead."
125+
)
115126
if run_spec.configuration.priority is None:
116127
run_spec.configuration.priority = RUN_PRIORITY_DEFAULT
117128
set_resources_defaults(run_spec.configuration.resources)

0 commit comments

Comments
 (0)