From 713afe3723cee7157113252a43e6ad4fa88627c8 Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:26:53 +0200 Subject: [PATCH 1/8] chore: replace dict by model_dump Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- substrafl/nodes/train_data_node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrafl/nodes/train_data_node.py b/substrafl/nodes/train_data_node.py index 5e248435..3c1b4d10 100644 --- a/substrafl/nodes/train_data_node.py +++ b/substrafl/nodes/train_data_node.py @@ -70,7 +70,7 @@ def init_states( }, tag=TaskType.INITIALIZATION, worker=self.organization_id, - ).dict() + ).model_dump() init_task.pop("function_key") init_task["remote_operation"] = operation.remote_struct @@ -181,7 +181,7 @@ def update_states( metadata=task_metadata, tag=TaskType.TRAIN, worker=self.organization_id, - ).dict() + ).model_dump() train_task.pop("function_key") train_task["remote_operation"] = operation.remote_struct From 705ea4da930d1bbbfccf03fa8a7f8af7cb4aede0 Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:15:48 +0200 Subject: [PATCH 2/8] chore: pudantic v2 Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- substrafl/dependency/schemas.py | 6 +++--- tests/settings.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/substrafl/dependency/schemas.py b/substrafl/dependency/schemas.py index 318d4773..b1dbe093 100644 --- a/substrafl/dependency/schemas.py +++ b/substrafl/dependency/schemas.py @@ -11,7 +11,7 @@ import substratools from pydantic import BaseModel from pydantic import Field -from pydantic import validator +from pydantic import field_validator import substrafl from substrafl import exceptions @@ -83,7 +83,7 @@ def __del__(self): """Delete the cache directory.""" self._delete_cache_directory() - @validator("local_installable_dependencies", "local_code") + @field_validator("local_installable_dependencies", "local_code", mode="before") def resolve_path(cls, v): # noqa: N805 """Resolve list of local code paths and check if they exist.""" not_existing_paths = list() @@ -101,7 +101,7 @@ def resolve_path(cls, v): # noqa: N805 return resolved_paths - @validator("local_installable_dependencies") + @field_validator("local_installable_dependencies", mode="before") def check_setup(cls, v): # noqa: N805 """Check the presence of a setup.py file or a pyproject.toml in the provided paths.""" not_installable = list() diff --git a/tests/settings.py b/tests/settings.py index 1a7702b2..b18eedde 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -7,7 +7,7 @@ import substra import yaml from pydantic import BaseModel -from pydantic import validator +from pydantic import field_validator CURRENT_DIR = Path(__file__).parent @@ -44,7 +44,7 @@ class Configuration(BaseModel): organizations: List[OrganizationCfg] - @validator("organizations") + @field_validator("organizations", mode="before") def minimal_number_of_organizations(cls, v): # noqa: N805 assert len(v) >= MIN_ORGANIZATIONS, ( "Not enough organizations defined in your configuration. " From bd07322a79b167a77a40bdff8984ada99547c8bf Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:08:05 +0200 Subject: [PATCH 3/8] chore: fix tests Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- substrafl/dependency/schemas.py | 11 ++++++----- substrafl/strategies/schemas.py | 3 +-- tests/settings.py | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/substrafl/dependency/schemas.py b/substrafl/dependency/schemas.py index b1dbe093..4c474154 100644 --- a/substrafl/dependency/schemas.py +++ b/substrafl/dependency/schemas.py @@ -10,6 +10,7 @@ import substra import substratools from pydantic import BaseModel +from pydantic import ConfigDict from pydantic import Field from pydantic import field_validator @@ -67,9 +68,7 @@ class Dependency(BaseModel): _wheels: List[Path] = [] _local_paths: List[Path] = [] _cache_directory: Optional[Path] = None - - class Config: - arbitrary_types_allowed = True + model_config = ConfigDict(arbitrary_types_allowed=True, allow_reuse=True) def __init__(self, *args, **kwargs): """Dependencies are computed at object initialization. @@ -83,7 +82,8 @@ def __del__(self): """Delete the cache directory.""" self._delete_cache_directory() - @field_validator("local_installable_dependencies", "local_code", mode="before") + @field_validator("local_installable_dependencies", "local_code") + @classmethod def resolve_path(cls, v): # noqa: N805 """Resolve list of local code paths and check if they exist.""" not_existing_paths = list() @@ -101,7 +101,8 @@ def resolve_path(cls, v): # noqa: N805 return resolved_paths - @field_validator("local_installable_dependencies", mode="before") + @field_validator("local_installable_dependencies") + @classmethod def check_setup(cls, v): # noqa: N805 """Check the presence of a setup.py file or a pyproject.toml in the provided paths.""" not_installable = list() diff --git a/substrafl/strategies/schemas.py b/substrafl/strategies/schemas.py index 535cfb1b..505d46ad 100644 --- a/substrafl/strategies/schemas.py +++ b/substrafl/strategies/schemas.py @@ -18,8 +18,7 @@ class StrategyName(str, Enum): class _Model(pydantic.BaseModel): """Base model configuration""" - class Config: - arbitrary_types_allowed = True + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) class FedAvgAveragedState(_Model): diff --git a/tests/settings.py b/tests/settings.py index b18eedde..4c285010 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -7,6 +7,7 @@ import substra import yaml from pydantic import BaseModel +from pydantic import ConfigDict from pydantic import field_validator CURRENT_DIR = Path(__file__).parent @@ -67,9 +68,7 @@ class Network(BaseModel): clients: List[substra.sdk.client.Client] msp_ids: Optional[List[str]] = None - class Config: - # Arbitrary type is used because substra Client is not pydantic compatible - arbitrary_types_allowed = True + model_config = ConfigDict(arbitrary_types_allowed=True) @property def n_organizations(self) -> int: From dac508a308830a4179d5c7017177391243e84abd Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:08:51 +0200 Subject: [PATCH 4/8] chore: fix tests Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- substrafl/dependency/schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrafl/dependency/schemas.py b/substrafl/dependency/schemas.py index 4c474154..3cd8d455 100644 --- a/substrafl/dependency/schemas.py +++ b/substrafl/dependency/schemas.py @@ -68,7 +68,7 @@ class Dependency(BaseModel): _wheels: List[Path] = [] _local_paths: List[Path] = [] _cache_directory: Optional[Path] = None - model_config = ConfigDict(arbitrary_types_allowed=True, allow_reuse=True) + model_config = ConfigDict(arbitrary_types_allowed=True) def __init__(self, *args, **kwargs): """Dependencies are computed at object initialization. From e840b2ee1777ccac440de55de19f814994856e05 Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:09:26 +0200 Subject: [PATCH 5/8] chore: fix tests Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- substrafl/dependency/schemas.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/substrafl/dependency/schemas.py b/substrafl/dependency/schemas.py index 3cd8d455..d127d3e6 100644 --- a/substrafl/dependency/schemas.py +++ b/substrafl/dependency/schemas.py @@ -83,7 +83,6 @@ def __del__(self): self._delete_cache_directory() @field_validator("local_installable_dependencies", "local_code") - @classmethod def resolve_path(cls, v): # noqa: N805 """Resolve list of local code paths and check if they exist.""" not_existing_paths = list() @@ -102,7 +101,6 @@ def resolve_path(cls, v): # noqa: N805 return resolved_paths @field_validator("local_installable_dependencies") - @classmethod def check_setup(cls, v): # noqa: N805 """Check the presence of a setup.py file or a pyproject.toml in the provided paths.""" not_installable = list() From 7eba36d3fd598798fcfbecbbdff1de6e21053dc6 Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:09:52 +0200 Subject: [PATCH 6/8] chore: fix tests Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- tests/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/settings.py b/tests/settings.py index 4c285010..9cead6c6 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -45,7 +45,7 @@ class Configuration(BaseModel): organizations: List[OrganizationCfg] - @field_validator("organizations", mode="before") + @field_validator("organizations") def minimal_number_of_organizations(cls, v): # noqa: N805 assert len(v) >= MIN_ORGANIZATIONS, ( "Not enough organizations defined in your configuration. " From 499650d16d9cc72c75173882b11a111dadf8bafd Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:11:42 +0200 Subject: [PATCH 7/8] chore: changelog Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c8ffe26..a42c6a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## \[Unreleased\] +### Fixed + +- Update schemas and tests to remove Pydantic v2 warnings ([#183](https://github.com/Substra/substrafl/pull/183)) + ## [0.42.0](https://github.com/Substra/substrafl/releases/tag/0.42.0) - 2023-10-18 ### Added From 1a925959988f473ca2b28e4f9160d4727f819674 Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:13:38 +0200 Subject: [PATCH 8/8] chore: comment Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- tests/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/settings.py b/tests/settings.py index 9cead6c6..8f68387b 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -68,6 +68,7 @@ class Network(BaseModel): clients: List[substra.sdk.client.Client] msp_ids: Optional[List[str]] = None + # Arbitrary type is used because substra Client is not pydantic compatible model_config = ConfigDict(arbitrary_types_allowed=True) @property