Skip to content

Commit 18f02bb

Browse files
Merge branch 'master' into 8292-create-custom-GenerateJsonSchema-for-resolving-references
2 parents 6d92976 + 7f0830f commit 18f02bb

File tree

69 files changed

+1632
-931
lines changed

Some content is hidden

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

69 files changed

+1632
-931
lines changed

packages/dask-task-models-library/src/dask_task_models_library/plugins/task_life_cycle_worker_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def transition(
3434
):
3535
_logger.info("Task '%s' transition from %s to %s", key, start, finish)
3636
assert self._worker # nosec
37+
assert isinstance(self._worker, Worker) # nosec
3738
self._worker.log_event(
3839
TASK_LIFE_CYCLE_EVENT.format(key=key),
3940
TaskLifeCycleState.from_worker_task_state(

packages/models-library/src/models_library/api_schemas_webserver/users.py

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from datetime import date, datetime
33
from enum import Enum
4-
from typing import Annotated, Any, Literal, Self
4+
from typing import Annotated, Any, Literal, Self, TypeAlias
55

66
import annotated_types
77
from common_library.basic_types import DEFAULT_FACTORY
@@ -18,6 +18,7 @@
1818
StringConstraints,
1919
ValidationInfo,
2020
field_validator,
21+
model_validator,
2122
)
2223
from pydantic.config import JsonDict
2324

@@ -83,7 +84,14 @@ class MyProfileRestGet(OutputSchemaWithoutCamelCase):
8384
login: LowerCaseEmailStr
8485
phone: str | None = None
8586

86-
role: Literal["ANONYMOUS", "GUEST", "USER", "TESTER", "PRODUCT_OWNER", "ADMIN"]
87+
role: Literal[
88+
"ANONYMOUS",
89+
"GUEST",
90+
"USER",
91+
"TESTER",
92+
"PRODUCT_OWNER",
93+
"ADMIN",
94+
]
8795
groups: MyGroupsGet | None = None
8896
gravatar_id: Annotated[str | None, Field(deprecated=True)] = None
8997

@@ -306,15 +314,41 @@ class UserAccountReject(InputSchema):
306314
email: EmailStr
307315

308316

317+
GlobString: TypeAlias = Annotated[
318+
str,
319+
StringConstraints(
320+
min_length=3, max_length=200, strip_whitespace=True, pattern=r"^[^%]*$"
321+
),
322+
]
323+
324+
309325
class UserAccountSearchQueryParams(RequestParameters):
310326
email: Annotated[
311-
str,
327+
GlobString | None,
312328
Field(
313-
min_length=3,
314-
max_length=200,
315329
description="complete or glob pattern for an email",
316330
),
317-
]
331+
] = None
332+
primary_group_id: Annotated[
333+
GroupID | None,
334+
Field(
335+
description="Filter by primary group ID",
336+
),
337+
] = None
338+
user_name: Annotated[
339+
GlobString | None,
340+
Field(
341+
description="complete or glob pattern for a username",
342+
),
343+
] = None
344+
345+
@model_validator(mode="after")
346+
def _validate_at_least_one_filter(self) -> Self:
347+
field_names = list(self.__class__.model_fields)
348+
if not any(getattr(self, field_name, None) for field_name in field_names):
349+
msg = f"At least one filter {field_names} must be provided"
350+
raise ValueError(msg)
351+
return self
318352

319353

320354
class UserAccountGet(OutputSchema):
@@ -340,9 +374,9 @@ class UserAccountGet(OutputSchema):
340374
# pre-registration NOTE: that some users have no pre-registartion and therefore all options here can be none
341375
pre_registration_id: int | None
342376
pre_registration_created: datetime | None
343-
invited_by: str | None = None
377+
invited_by: UserNameID | None = None
344378
account_request_status: AccountRequestStatus | None
345-
account_request_reviewed_by: UserID | None = None
379+
account_request_reviewed_by: UserNameID | None = None
346380
account_request_reviewed_at: datetime | None = None
347381

348382
# user status

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Annotated, TypeAlias
33

44
from common_library.users_enums import UserRole
5-
from models_library.basic_types import IDStr
65
from pydantic import BaseModel, ConfigDict, Field, PositiveInt, StringConstraints
76
from pydantic.config import JsonDict
87
from typing_extensions import ( # https://docs.pydantic.dev/latest/api/standard_library_types/#typeddict
@@ -12,8 +11,9 @@
1211
from .emails import LowerCaseEmailStr
1312

1413
UserID: TypeAlias = PositiveInt
15-
UserNameID: TypeAlias = IDStr
16-
14+
UserNameID: TypeAlias = Annotated[
15+
str, StringConstraints(strip_whitespace=True, min_length=1, max_length=100)
16+
]
1717

1818
FirstNameStr: TypeAlias = Annotated[
1919
str, StringConstraints(strip_whitespace=True, max_length=255)

packages/pytest-simcore/src/pytest_simcore/pydantic_models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def _is_model_cls(obj) -> bool:
9797
assert inspect.ismodule(module)
9898

9999
for model_name, model_cls in inspect.getmembers(module, _is_model_cls):
100-
101100
yield from iter_model_examples_in_class(model_cls, model_name)
102101

103102

@@ -172,7 +171,7 @@ def model_cls_examples(model_cls: type[BaseModel]) -> dict[str, dict[str, Any]]:
172171
"""
173172
warnings.warn(
174173
"The 'model_cls_examples' fixture is deprecated and will be removed in a future version. "
175-
"Please use 'iter_model_example_in_class' or 'iter_model_examples_in_module' as an alternative.",
174+
"Please use 'iter_model_examples_in_class' or 'iter_model_examples_in_module' as an alternative.",
176175
DeprecationWarning,
177176
stacklevel=2,
178177
)

services/api-server/setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ commit_args = --no-verify
1111
asyncio_mode = auto
1212
asyncio_default_fixture_loop_scope = function
1313
addopts = --strict-markers
14-
markers =
14+
markers =
1515
slow: marks tests as slow (deselect with '-m "not slow"')
1616
acceptance_test: "marks tests as 'acceptance tests' i.e. does the system do what the user expects? Typically those are workflows."
1717
testit: "marks test to run during development"
1818

1919
[mypy]
20-
plugins =
20+
plugins =
2121
pydantic.mypy
2222
sqlalchemy.ext.mypy.plugin

services/api-server/src/simcore_service_api_server/models/schemas/profiles.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class ProfileCommon(BaseModel):
1313
last_name: LastNameStr | None = Field(None, examples=["Maxwell"])
1414

1515

16-
class ProfileUpdate(ProfileCommon):
17-
...
16+
class ProfileUpdate(ProfileCommon): ...
1817

1918

2019
class UserRoleEnum(StrAutoEnum):

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ class ComputationalBackendSettings(BaseCustomSettings):
9999
),
100100
] = datetime.timedelta(minutes=10)
101101

102+
COMPUTATIONAL_BACKEND_MAX_WAITING_FOR_RETRIEVING_RESULTS: Annotated[
103+
datetime.timedelta,
104+
Field(
105+
description="maximum time the computational scheduler waits until retrieving results from the computational backend is failed"
106+
"(default to seconds, or see https://pydantic-docs.helpmanual.io/usage/types/#datetime-types for string formatting)."
107+
),
108+
] = datetime.timedelta(minutes=10)
109+
102110
@cached_property
103111
def default_cluster(self) -> BaseCluster:
104112
return BaseCluster(

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
from contextlib import suppress
12
from datetime import datetime
23
from typing import Annotated, Any
34

45
from models_library.projects import ProjectID
56
from models_library.projects_nodes_io import NodeID
67
from models_library.projects_state import RunningState
78
from models_library.resource_tracker import HardwareInfo
8-
from pydantic import BaseModel, BeforeValidator, ConfigDict, PositiveInt
9+
from pydantic import (
10+
BaseModel,
11+
BeforeValidator,
12+
ConfigDict,
13+
PositiveInt,
14+
field_validator,
15+
)
16+
from simcore_postgres_database.models.comp_pipeline import StateType
917

18+
from ..utils.db import DB_TO_RUNNING_STATE
1019
from .comp_tasks import BaseCompTaskAtDB, Image
1120

1221

@@ -100,3 +109,15 @@ class CompRunSnapshotTaskDBGet(BaseModel):
100109
started_at: datetime | None
101110
ended_at: datetime | None
102111
iteration: PositiveInt
112+
113+
@field_validator("state", mode="before")
114+
@classmethod
115+
def convert_result_from_state_type_enum_if_needed(cls, v):
116+
if isinstance(v, str):
117+
# try to convert to a StateType, if it fails the validations will continue
118+
# and pydantic will try to convert it to a RunninState later on
119+
with suppress(ValueError):
120+
v = StateType(v)
121+
if isinstance(v, StateType):
122+
return RunningState(DB_TO_RUNNING_STATE[StateType(v)])
123+
return v

0 commit comments

Comments
 (0)