Skip to content

Commit 34c9f3e

Browse files
authored
⬆️ pydantic migration catalog (#6629)
1 parent 05cff9e commit 34c9f3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2383
-970
lines changed

packages/models-library/src/models_library/api_schemas_catalog/services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ class ServiceGetV2(BaseModel):
244244
quality: dict[str, Any] = {}
245245

246246
history: list[ServiceRelease] = Field(
247-
default=[],
247+
default_factory=list,
248248
description="history of releases for this service at this point in time, starting from the newest to the oldest."
249249
" It includes current release.",
250+
json_schema_extra={"default": []},
250251
)
251252

252253
model_config = ConfigDict(

packages/models-library/src/models_library/app_diagnostics.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ class AppStatusCheck(BaseModel):
77
app_name: str = Field(..., description="Application name")
88
version: str = Field(..., description="Application's version")
99
services: dict[str, Any] = Field(
10-
default={}, description="Other backend services connected from this service"
10+
default_factory=dict,
11+
description="Other backend services connected from this service",
12+
json_schema_extra={"default": {}},
1113
)
1214

1315
sessions: dict[str, Any] | None = Field(
14-
default={},
16+
default_factory=dict,
1517
description="Client sessions info. If single session per app, then is denoted as main",
18+
json_schema_extra={"default": {}},
1619
)
1720

1821
url: AnyUrl | None = Field(

packages/models-library/src/models_library/services_metadata_editable.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class ServiceMetaDataEditable(ServiceBaseDisplay):
3333
"If now>=deprecated, the service is retired",
3434
)
3535
classifiers: list[str] | None
36-
quality: dict[str, Any] = {}
36+
quality: dict[str, Any] = Field(
37+
default_factory=dict, json_schema_extra={"default": {}}
38+
)
3739

3840
model_config = ConfigDict(
3941
json_schema_extra={
@@ -60,6 +62,7 @@ class ServiceMetaDataEditable(ServiceBaseDisplay):
6062
for n in range(1, 11)
6163
},
6264
},
65+
"classifiers": [],
6366
}
6467
}
6568
)

packages/models-library/src/models_library/services_resources.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
CPU_100_PERCENT: Final[int] = int(1 * GIGA)
3434

3535

36-
class ResourceValue(BaseModel):
36+
class ResourceValue(BaseModel, validate_assignment=True):
3737
limit: StrictInt | StrictFloat | str
3838
reservation: StrictInt | StrictFloat | str
3939

4040
@model_validator(mode="before")
4141
@classmethod
4242
def _ensure_limits_are_equal_or_above_reservations(cls, values):
43+
# WARNING: this does not validate ON-ASSIGNMENT!
4344
if isinstance(values["reservation"], str):
4445
# in case of string, the limit is the same as the reservation
4546
values["limit"] = values["reservation"]
@@ -56,10 +57,8 @@ def set_reservation_same_as_limit(self) -> None:
5657
def set_value(self, value: StrictInt | StrictFloat | str) -> None:
5758
self.limit = self.reservation = value
5859

59-
model_config = ConfigDict(validate_assignment=True)
6060

61-
62-
ResourcesDict = dict[ResourceName, ResourceValue]
61+
ResourcesDict: TypeAlias = dict[ResourceName, ResourceValue]
6362

6463

6564
class BootMode(StrAutoEnum):
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
from models_library.services_resources import ResourceValue
3+
4+
5+
@pytest.mark.xfail()
6+
def test_reservation_is_cap_by_limit_on_assigment_pydantic_2_bug():
7+
8+
res = ResourceValue(limit=10, reservation=30)
9+
assert res.limit == 10
10+
assert res.reservation == 10
11+
12+
# https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.validate_assignment
13+
# before-validators DO NOT work on Assignment!!!
14+
# SEE https://github.com/pydantic/pydantic/issues/7105
15+
res.reservation = 30
16+
assert res.reservation == 10
17+
18+
# update here is not validated neither
19+
#
20+
# res.model_copy(update={"reservation": 30})
21+
#

packages/settings-library/src/settings_library/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pydantic import Field, PositiveInt
22

33
from .base import BaseCustomSettings
4-
from .basic_types import BuildTargetEnum
4+
from .basic_types import BootMode, BuildTargetEnum
55

66

77
class BaseApplicationSettings(BaseCustomSettings):
@@ -16,6 +16,7 @@ class BaseApplicationSettings(BaseCustomSettings):
1616
SC_VCS_URL: str | None = None
1717

1818
# @Dockerfile
19+
SC_BOOT_MODE: BootMode | None = None
1920
SC_BOOT_TARGET: BuildTargetEnum | None = None
2021
SC_HEALTHCHECK_TIMEOUT: PositiveInt | None = Field(
2122
default=None,

scripts/common-service.Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ _assert_target_defined:
192192

193193

194194
# specification of the used openapi-generator-cli (see also https://github.com/ITISFoundation/openapi-generator)
195-
OPENAPI_GENERATOR_NAME := itisfoundation/openapi-generator-cli-openapi-generator-v4.2.3
196-
OPENAPI_GENERATOR_TAG := v0
195+
OPENAPI_GENERATOR_NAME := openapitools/openapi-generator-cli
196+
OPENAPI_GENERATOR_TAG := latest
197197
OPENAPI_GENERATOR_IMAGE := $(OPENAPI_GENERATOR_NAME):$(OPENAPI_GENERATOR_TAG)
198198

199199
define validate_openapi_specs

services/api-server/Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ reqs: ## compiles pip requirements (.in -> .txt)
1414
cp .env-devel $@
1515

1616

17-
# specification of the used openapi-generator-cli (see also https://github.com/ITISFoundation/openapi-generator)
18-
OPENAPI_GENERATOR_NAME := openapitools/openapi-generator-cli
19-
OPENAPI_GENERATOR_TAG := latest
20-
OPENAPI_GENERATOR_IMAGE := $(OPENAPI_GENERATOR_NAME):$(OPENAPI_GENERATOR_TAG)
21-
2217
define _create_and_validate_openapi
2318
# generating openapi specs file under $< (NOTE: Skips DEV FEATURES since this OAS is the 'offically released'!)
2419
@source .env; \

services/api-server/src/simcore_service_api_server/exceptions/handlers/_http_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
async def http_exception_handler(request: Request, exc: Exception) -> JSONResponse:
99
assert request # nosec
10-
assert isinstance(exc, HTTPException)
10+
assert isinstance(exc, HTTPException) # nosec
1111

1212
return create_error_json_response(exc.detail, status_code=exc.status_code)

services/catalog/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.0
1+
0.6.0

0 commit comments

Comments
 (0)