33from models_library .basic_regex import SIMPLE_VERSION_RE
44from models_library .services import ServiceMetaDataPublished
55from packaging import version
6- from pydantic import BaseModel , ByteSize , Extra , Field , validator
6+ from pydantic import BaseModel , ByteSize , ConfigDict , Field , field_validator
77
88LEGACY_INTEGRATION_VERSION = version .Version ("0" )
99PROGRESS_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"
0 commit comments