Skip to content

Commit c34c99c

Browse files
run bump-pydantic
1 parent 7326380 commit c34c99c

File tree

7 files changed

+93
-176
lines changed

7 files changed

+93
-176
lines changed

services/director-v2/src/simcore_service_director_v2/core/dynamic_services_settings/sidecar.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ensure_unique_dict_values_validator,
1010
ensure_unique_list_values_validator,
1111
)
12-
from pydantic import Field, PositiveInt, validator
12+
from pydantic import AliasChoices, field_validator, Field, PositiveInt
1313
from settings_library.aws_s3_cli import AwsS3CliSettings
1414
from settings_library.base import BaseCustomSettings
1515
from settings_library.efs import AwsEfsSettings
@@ -45,7 +45,7 @@ class RCloneSettings(SettingsLibraryRCloneSettings):
4545
description="VFS operation mode, defines how and when the disk cache is synced",
4646
)
4747

48-
@validator("R_CLONE_POLL_INTERVAL_SECONDS")
48+
@field_validator("R_CLONE_POLL_INTERVAL_SECONDS")
4949
@classmethod
5050
def enforce_r_clone_requirement(cls, v: int, values) -> PositiveInt:
5151
dir_cache_time = values["R_CLONE_DIR_CACHE_TIME_SECONDS"]
@@ -60,7 +60,7 @@ class PlacementSettings(BaseCustomSettings):
6060
# https://docs.docker.com/engine/swarm/services/#control-service-placement.
6161
DIRECTOR_V2_SERVICES_CUSTOM_CONSTRAINTS: list[DockerPlacementConstraint] = Field(
6262
default_factory=list,
63-
example='["node.labels.region==east", "one!=yes"]',
63+
examples=['["node.labels.region==east", "one!=yes"]'],
6464
)
6565

6666
DIRECTOR_V2_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS: dict[
@@ -72,20 +72,18 @@ class PlacementSettings(BaseCustomSettings):
7272
"see https://github.com/ITISFoundation/osparc-simcore/issues/5250 "
7373
"When `None` (default), uses generic resources"
7474
),
75-
example='{"AIRAM": "node.labels.custom==true"}',
75+
examples=['{"AIRAM": "node.labels.custom==true"}'],
7676
)
7777

78-
_unique_custom_constraints = validator(
78+
_unique_custom_constraints = field_validator(
7979
"DIRECTOR_V2_SERVICES_CUSTOM_CONSTRAINTS",
80-
allow_reuse=True,
8180
)(ensure_unique_list_values_validator)
8281

83-
_unique_resource_placement_constraints_substitutions = validator(
82+
_unique_resource_placement_constraints_substitutions = field_validator(
8483
"DIRECTOR_V2_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS",
85-
allow_reuse=True,
8684
)(ensure_unique_dict_values_validator)
8785

88-
@validator("DIRECTOR_V2_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS")
86+
@field_validator("DIRECTOR_V2_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS")
8987
@classmethod
9088
def warn_if_any_values_provided(cls, value: dict) -> dict:
9189
if len(value) > 0:
@@ -101,40 +99,40 @@ def warn_if_any_values_provided(cls, value: dict) -> dict:
10199
class DynamicSidecarSettings(BaseCustomSettings, MixinLoggingSettings):
102100
DYNAMIC_SIDECAR_ENDPOINT_SPECS_MODE_DNSRR_ENABLED: bool = Field( # doc: https://docs.docker.com/engine/swarm/networking/#configure-service-discovery
103101
default=False,
104-
env=["DYNAMIC_SIDECAR_ENDPOINT_SPECS_MODE_DNSRR_ENABLED"],
102+
validation_alias=AliasChoices("DYNAMIC_SIDECAR_ENDPOINT_SPECS_MODE_DNSRR_ENABLED"),
105103
description="dynamic-sidecar's service 'endpoint_spec' with {'Mode': 'dnsrr'}",
106104
)
107105
DYNAMIC_SIDECAR_SC_BOOT_MODE: BootModeEnum = Field(
108106
...,
109107
description="Boot mode used for the dynamic-sidecar services"
110108
"By defaults, it uses the same boot mode set for the director-v2",
111-
env=["DYNAMIC_SIDECAR_SC_BOOT_MODE", "SC_BOOT_MODE"],
109+
validation_alias=AliasChoices("DYNAMIC_SIDECAR_SC_BOOT_MODE", "SC_BOOT_MODE"),
112110
)
113111

114112
DYNAMIC_SIDECAR_LOG_LEVEL: str = Field(
115113
"WARNING",
116114
description="log level of the dynamic sidecar"
117115
"If defined, it captures global env vars LOG_LEVEL and LOGLEVEL from the director-v2 service",
118-
env=["DYNAMIC_SIDECAR_LOG_LEVEL", "LOG_LEVEL", "LOGLEVEL"],
116+
validation_alias=AliasChoices("DYNAMIC_SIDECAR_LOG_LEVEL", "LOG_LEVEL", "LOGLEVEL"),
119117
)
120118

121119
DYNAMIC_SIDECAR_IMAGE: str = Field(
122120
...,
123-
regex=DYNAMIC_SIDECAR_DOCKER_IMAGE_RE,
121+
pattern=DYNAMIC_SIDECAR_DOCKER_IMAGE_RE,
124122
description="used by the director to start a specific version of the dynamic-sidecar",
125123
)
126124

127-
DYNAMIC_SIDECAR_R_CLONE_SETTINGS: RCloneSettings = Field(auto_default_from_env=True)
125+
DYNAMIC_SIDECAR_R_CLONE_SETTINGS: RCloneSettings = Field(json_schema_extra={"auto_default_from_env": True})
128126

129127
DYNAMIC_SIDECAR_AWS_S3_CLI_SETTINGS: AwsS3CliSettings | None = Field(
130-
auto_default_from_env=True
128+
json_schema_extra={"auto_default_from_env": True}
131129
)
132130
DYNAMIC_SIDECAR_EFS_SETTINGS: AwsEfsSettings | None = Field(
133-
auto_default_from_env=True
131+
json_schema_extra={"auto_default_from_env": True}
134132
)
135133

136134
DYNAMIC_SIDECAR_PLACEMENT_SETTINGS: PlacementSettings = Field(
137-
auto_default_from_env=True
135+
json_schema_extra={"auto_default_from_env": True}
138136
)
139137

140138
#
@@ -144,7 +142,7 @@ class DynamicSidecarSettings(BaseCustomSettings, MixinLoggingSettings):
144142
DYNAMIC_SIDECAR_MOUNT_PATH_DEV: Path | None = Field(
145143
None,
146144
description="Host path to the dynamic-sidecar project. Used as source path to mount to the dynamic-sidecar [DEVELOPMENT ONLY]",
147-
example="osparc-simcore/services/dynamic-sidecar",
145+
examples=["osparc-simcore/services/dynamic-sidecar"],
148146
)
149147

150148
DYNAMIC_SIDECAR_PORT: PortInt = Field(
@@ -157,9 +155,10 @@ class DynamicSidecarSettings(BaseCustomSettings, MixinLoggingSettings):
157155
description="Publishes the service on localhost for debuging and testing [DEVELOPMENT ONLY]"
158156
"Can be used to access swagger doc from the host as http://127.0.0.1:30023/dev/doc "
159157
"where 30023 is the host published port",
158+
validate_default=True
160159
)
161160

162-
@validator("DYNAMIC_SIDECAR_MOUNT_PATH_DEV", pre=True)
161+
@field_validator("DYNAMIC_SIDECAR_MOUNT_PATH_DEV", mode="before")
163162
@classmethod
164163
def auto_disable_if_production(cls, v, values):
165164
if v and values.get("DYNAMIC_SIDECAR_SC_BOOT_MODE") == BootModeEnum.PRODUCTION:
@@ -170,7 +169,7 @@ def auto_disable_if_production(cls, v, values):
170169
return None
171170
return v
172171

173-
@validator("DYNAMIC_SIDECAR_EXPOSE_PORT", pre=True, always=True)
172+
@field_validator("DYNAMIC_SIDECAR_EXPOSE_PORT", mode="before")
174173
@classmethod
175174
def auto_enable_if_development(cls, v, values):
176175
if (
@@ -180,12 +179,12 @@ def auto_enable_if_development(cls, v, values):
180179
return True
181180
return v
182181

183-
@validator("DYNAMIC_SIDECAR_IMAGE", pre=True)
182+
@field_validator("DYNAMIC_SIDECAR_IMAGE", mode="before")
184183
@classmethod
185184
def strip_leading_slashes(cls, v: str) -> str:
186185
return v.lstrip("/")
187186

188-
@validator("DYNAMIC_SIDECAR_LOG_LEVEL")
187+
@field_validator("DYNAMIC_SIDECAR_LOG_LEVEL")
189188
@classmethod
190189
def _validate_log_level(cls, value) -> str:
191190
log_level: str = cls.validate_log_level(value)

services/director-v2/src/simcore_service_director_v2/core/settings.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
ClusterTypeInModel,
2121
NoAuthentication,
2222
)
23-
from pydantic import AnyHttpUrl, AnyUrl, Field, NonNegativeInt, validator
23+
from pydantic import AliasChoices, field_validator, AnyHttpUrl, AnyUrl, Field, NonNegativeInt
2424
from settings_library.base import BaseCustomSettings
2525
from settings_library.catalog import CatalogSettings
2626
from settings_library.docker_registry import RegistrySettings
@@ -107,7 +107,7 @@ def default_cluster(self) -> Cluster:
107107
type=ClusterTypeInModel.ON_PREMISE,
108108
)
109109

110-
@validator("COMPUTATIONAL_BACKEND_DEFAULT_CLUSTER_AUTH", pre=True)
110+
@field_validator("COMPUTATIONAL_BACKEND_DEFAULT_CLUSTER_AUTH", mode="before")
111111
@classmethod
112112
def _empty_auth_is_none(cls, v):
113113
if not v:
@@ -122,14 +122,14 @@ class AppSettings(BaseCustomSettings, MixinLoggingSettings):
122122

123123
LOG_LEVEL: LogLevel = Field(
124124
LogLevel.INFO.value,
125-
env=["DIRECTOR_V2_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"],
125+
validation_alias=AliasChoices("DIRECTOR_V2_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"),
126126
)
127127
DIRECTOR_V2_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
128128
default=False,
129-
env=[
129+
validation_alias=AliasChoices(
130130
"DIRECTOR_V2_LOG_FORMAT_LOCAL_DEV_ENABLED",
131131
"LOG_FORMAT_LOCAL_DEV_ENABLED",
132-
],
132+
),
133133
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
134134
)
135135
DIRECTOR_V2_DEV_FEATURES_ENABLED: bool = False
@@ -161,7 +161,7 @@ class AppSettings(BaseCustomSettings, MixinLoggingSettings):
161161
DIRECTOR_V2_REMOTE_DEBUGGING_PORT: PortInt | None
162162

163163
# extras
164-
SWARM_STACK_NAME: str = Field("undefined-please-check", env="SWARM_STACK_NAME")
164+
SWARM_STACK_NAME: str = Field("undefined-please-check", validation_alias="SWARM_STACK_NAME")
165165
SERVICE_TRACKING_HEARTBEAT: datetime.timedelta = Field(
166166
default=DEFAULT_RESOURCE_USAGE_HEARTBEAT_INTERVAL,
167167
description="Service scheduler heartbeat (everytime a heartbeat is sent into RabbitMQ)"
@@ -227,10 +227,10 @@ class AppSettings(BaseCustomSettings, MixinLoggingSettings):
227227
description="Base URL used to access the public api e.g. http://127.0.0.1:6000 for development or https://api.osparc.io",
228228
)
229229
DIRECTOR_V2_TRACING: TracingSettings | None = Field(
230-
auto_default_from_env=True, description="settings for opentelemetry tracing"
230+
json_schema_extra={"auto_default_from_env": True}, description="settings for opentelemetry tracing"
231231
)
232232

233-
@validator("LOG_LEVEL", pre=True)
233+
@field_validator("LOG_LEVEL", mode="before")
234234
@classmethod
235235
def _validate_loglevel(cls, value: str) -> str:
236236
log_level: str = cls.validate_log_level(value)

services/director-v2/src/simcore_service_director_v2/models/comp_pipelines.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import networkx as nx
55
from models_library.projects import ProjectID
66
from models_library.projects_state import RunningState
7-
from pydantic import BaseModel, validator
7+
from pydantic import field_validator, ConfigDict, BaseModel
88
from simcore_postgres_database.models.comp_pipeline import StateType
99

1010
from ..utils.db import DB_TO_RUNNING_STATE
@@ -15,7 +15,7 @@ class CompPipelineAtDB(BaseModel):
1515
dag_adjacency_list: dict[str, list[str]] # json serialization issue if using NodeID
1616
state: RunningState
1717

18-
@validator("state", pre=True)
18+
@field_validator("state", mode="before")
1919
@classmethod
2020
def convert_state_from_state_type_enum_if_needed(cls, v):
2121
if isinstance(v, str):
@@ -27,7 +27,7 @@ def convert_state_from_state_type_enum_if_needed(cls, v):
2727
return RunningState(DB_TO_RUNNING_STATE[StateType(v)])
2828
return v
2929

30-
@validator("dag_adjacency_list", pre=True)
30+
@field_validator("dag_adjacency_list", mode="before")
3131
@classmethod
3232
def auto_convert_dag(cls, v):
3333
# this enforcement is here because the serialization using json is not happy with non str Dict keys, also comparison gets funny if the lists are having sometimes UUIDs or str.
@@ -41,11 +41,9 @@ def get_graph(self) -> nx.DiGraph:
4141
self.dag_adjacency_list, create_using=nx.DiGraph # type: ignore[arg-type] # list is an Iterable but dict is Invariant
4242
),
4343
)
44-
45-
class Config:
46-
orm_mode = True
47-
48-
schema_extra: ClassVar[dict[str, Any]] = {
44+
model_config = ConfigDict(
45+
from_attributes=True,
46+
json_schema_extra={
4947
"examples": [
5048
# DB model
5149
{
@@ -61,3 +59,4 @@ class Config:
6159
}
6260
]
6361
}
62+
)

services/director-v2/src/simcore_service_director_v2/models/comp_runs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from models_library.projects_nodes_io import NodeID
88
from models_library.projects_state import RunningState
99
from models_library.users import UserID
10-
from pydantic import BaseModel, PositiveInt, validator
10+
from pydantic import field_validator, ConfigDict, BaseModel, PositiveInt
1111
from simcore_postgres_database.models.comp_pipeline import StateType
1212

1313
from ..utils.db import DB_TO_RUNNING_STATE
@@ -49,7 +49,7 @@ class CompRunsAtDB(BaseModel):
4949
metadata: RunMetadataDict = RunMetadataDict()
5050
use_on_demand_clusters: bool
5151

52-
@validator("result", pre=True)
52+
@field_validator("result", mode="before")
5353
@classmethod
5454
def convert_result_from_state_type_enum_if_needed(cls, v):
5555
if isinstance(v, str):
@@ -61,30 +61,29 @@ def convert_result_from_state_type_enum_if_needed(cls, v):
6161
return RunningState(DB_TO_RUNNING_STATE[StateType(v)])
6262
return v
6363

64-
@validator("cluster_id", pre=True)
64+
@field_validator("cluster_id", mode="before")
6565
@classmethod
6666
def convert_null_to_default_cluster_id(cls, v):
6767
if v is None:
6868
v = DEFAULT_CLUSTER_ID
6969
return v
7070

71-
@validator("created", "modified", "started", "ended")
71+
@field_validator("created", "modified", "started", "ended")
7272
@classmethod
7373
def ensure_utc(cls, v: datetime.datetime | None) -> datetime.datetime | None:
7474
if v is not None and v.tzinfo is None:
7575
v = v.replace(tzinfo=datetime.timezone.utc)
7676
return v
7777

78-
@validator("metadata", pre=True)
78+
@field_validator("metadata", mode="before")
7979
@classmethod
8080
def convert_null_to_empty_metadata(cls, v):
8181
if v is None:
8282
v = RunMetadataDict()
8383
return v
84-
85-
class Config:
86-
orm_mode = True
87-
schema_extra: ClassVar[dict[str, Any]] = {
84+
model_config = ConfigDict(
85+
from_attributes=True,
86+
json_schema_extra={
8887
"examples": [
8988
# DB model
9089
{
@@ -120,3 +119,4 @@ class Config:
120119
},
121120
]
122121
}
122+
)

0 commit comments

Comments
 (0)