Skip to content

Commit 7c4314b

Browse files
authored
Fix mutually exclusive fields validation (#3598)
Pydantic validators should raise `ValueError`, `TypeError`, or `AssertionError`, not `KeyError`.
1 parent c9cf54e commit 7c4314b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ class BaseRunConfiguration(CoreModel):
546546
@validator("python", pre=True, always=True)
547547
def convert_python(cls, v, values) -> Optional[PythonVersion]:
548548
if v is not None and values.get("image"):
549-
raise KeyError("`image` and `python` are mutually exclusive fields")
549+
raise ValueError("`image` and `python` are mutually exclusive fields")
550550
if isinstance(v, float):
551551
v = str(v)
552552
if v == "3.1":
@@ -558,11 +558,11 @@ def convert_python(cls, v, values) -> Optional[PythonVersion]:
558558
@validator("docker", pre=True, always=True)
559559
def _docker(cls, v, values) -> Optional[bool]:
560560
if v is True and values.get("image"):
561-
raise KeyError("`image` and `docker` are mutually exclusive fields")
561+
raise ValueError("`image` and `docker` are mutually exclusive fields")
562562
if v is True and values.get("python"):
563-
raise KeyError("`python` and `docker` are mutually exclusive fields")
563+
raise ValueError("`python` and `docker` are mutually exclusive fields")
564564
if v is True and values.get("nvcc"):
565-
raise KeyError("`nvcc` and `docker` are mutually exclusive fields")
565+
raise ValueError("`nvcc` and `docker` are mutually exclusive fields")
566566
# Ideally, we'd like to also prohibit privileged=False when docker=True,
567567
# but it's not possible to do so without breaking backwards compatibility.
568568
return v

0 commit comments

Comments
 (0)