Skip to content

Commit ca1676e

Browse files
run bump-pydantic
1 parent 3e2cd3d commit ca1676e

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/models.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from models_library.basic_regex import SIMPLE_VERSION_RE
44
from models_library.services import ServiceMetaDataPublished
55
from packaging import version
6-
from pydantic import BaseModel, ByteSize, Extra, Field, validator
6+
from pydantic import BaseModel, ByteSize, ConfigDict, Field, field_validator
77

88
LEGACY_INTEGRATION_VERSION = version.Version("0")
99
PROGRESS_REGEXP: re.Pattern[str] = re.compile(
@@ -36,20 +36,21 @@ class ContainerHostConfig(BaseModel):
3636
default=None,
3737
alias="MemorySwap",
3838
description="Total memory limit (memory + swap). Set as -1 to enable unlimited swap.",
39+
validate_default=True,
3940
)
4041
nano_cpus: int = Field(
4142
..., alias="NanoCPUs", description="CPU quota in units of 10-9 CPUs"
4243
)
4344

44-
@validator("memory_swap", pre=True, always=True)
45+
@field_validator("memory_swap", mode="before")
4546
@classmethod
4647
def ensure_no_memory_swap_means_no_swap(cls, v, values):
4748
if v is None:
4849
# if not set it will be the same value as memory to ensure swap is disabled
4950
return values["memory"]
5051
return v
5152

52-
@validator("memory_swap")
53+
@field_validator("memory_swap")
5354
@classmethod
5455
def ensure_memory_swap_cannot_be_unlimited_nor_smaller_than_memory(cls, v, values):
5556
if v < values["memory"]:
@@ -71,26 +72,24 @@ class ImageLabels(BaseModel):
7172
default=str(LEGACY_INTEGRATION_VERSION),
7273
alias="integration-version",
7374
description="integration version number",
74-
regex=SIMPLE_VERSION_RE,
75+
pattern=SIMPLE_VERSION_RE,
7576
examples=["1.0.0"],
7677
)
7778
progress_regexp: str = Field(
7879
default=PROGRESS_REGEXP.pattern,
7980
alias="progress_regexp",
8081
description="regexp pattern for detecting computational service's progress",
8182
)
83+
model_config = ConfigDict(extra="ignore")
8284

83-
class Config:
84-
extra = Extra.ignore
85-
86-
@validator("integration_version", pre=True)
85+
@field_validator("integration_version", mode="before")
8786
@classmethod
8887
def default_integration_version(cls, v):
8988
if v is None:
9089
return ImageLabels().integration_version
9190
return v
9291

93-
@validator("progress_regexp", pre=True)
92+
@field_validator("progress_regexp", mode="before")
9493
@classmethod
9594
def default_progress_regexp(cls, v):
9695
if v is None:
@@ -104,6 +103,6 @@ def get_progress_regexp(self) -> re.Pattern[str]:
104103
return re.compile(self.progress_regexp)
105104

106105

107-
assert set(ImageLabels.__fields__).issubset(
108-
ServiceMetaDataPublished.__fields__
106+
assert set(ImageLabels.model_fields).issubset(
107+
ServiceMetaDataPublished.model_fields
109108
), "ImageLabels must be compatible with ServiceDockerData"

services/dask-sidecar/src/simcore_service_dask_sidecar/settings.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any
33

44
from models_library.basic_types import LogLevel
5-
from pydantic import Field, validator
5+
from pydantic import AliasChoices, Field, field_validator
66
from settings_library.base import BaseCustomSettings
77
from settings_library.utils_logging import MixinLoggingSettings
88

@@ -14,7 +14,9 @@ class Settings(BaseCustomSettings, MixinLoggingSettings):
1414
SC_BOOT_MODE: str | None = None
1515
LOG_LEVEL: LogLevel = Field(
1616
LogLevel.INFO.value,
17-
env=["DASK_SIDECAR_LOGLEVEL", "SIDECAR_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"],
17+
validation_alias=AliasChoices(
18+
"DASK_SIDECAR_LOGLEVEL", "SIDECAR_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"
19+
),
1820
)
1921

2022
# sidecar config ---
@@ -37,7 +39,9 @@ class Settings(BaseCustomSettings, MixinLoggingSettings):
3739

3840
DASK_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
3941
default=False,
40-
env=["DASK_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED"],
42+
validation_alias=AliasChoices(
43+
"DASK_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED"
44+
),
4145
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
4246
)
4347

@@ -50,7 +54,7 @@ def as_worker(self) -> bool:
5054
assert self.DASK_SCHEDULER_HOST is not None # nosec
5155
return as_worker
5256

53-
@validator("LOG_LEVEL", pre=True)
57+
@field_validator("LOG_LEVEL", mode="before")
5458
@classmethod
5559
def _validate_loglevel(cls, value: Any) -> str:
5660
return cls.validate_log_level(f"{value}")

0 commit comments

Comments
 (0)