Skip to content

Commit b6194a1

Browse files
fix validator
1 parent c14aaff commit b6194a1

File tree

1 file changed

+14
-5
lines changed
  • packages/models-library/src/models_library/api_schemas_directorv2

1 file changed

+14
-5
lines changed

packages/models-library/src/models_library/api_schemas_directorv2/comp_tasks.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
from typing import Any, TypeAlias
22

33
from models_library.basic_types import IDStr
4-
from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field, field_validator
4+
from pydantic import (
5+
AnyHttpUrl,
6+
AnyUrl,
7+
BaseModel,
8+
Field,
9+
ValidationInfo,
10+
field_validator,
11+
)
512

613
from ..clusters import ClusterID
714
from ..projects import ProjectID
@@ -52,16 +59,18 @@ class ComputationCreate(BaseModel):
5259

5360
@field_validator("product_name")
5461
@classmethod
55-
def ensure_product_name_defined_if_computation_starts(cls, v, values):
56-
if "start_pipeline" in values and values["start_pipeline"] and v is None:
62+
def _ensure_product_name_defined_if_computation_starts(
63+
cls, v, info: ValidationInfo
64+
):
65+
if info.data.get("start_pipeline") and v is None:
5766
msg = "product_name must be set if computation shall start!"
5867
raise ValueError(msg)
5968
return v
6069

6170
@field_validator("use_on_demand_clusters")
6271
@classmethod
63-
def ensure_expected_options(cls, v, values):
64-
if v is True and ("cluster_id" in values and values["cluster_id"] is not None):
72+
def _ensure_expected_options(cls, v, info: ValidationInfo):
73+
if v and info.data.get("cluster_id") is not None:
6574
msg = "cluster_id cannot be set if use_on_demand_clusters is set"
6675
raise ValueError(msg)
6776
return v

0 commit comments

Comments
 (0)