Skip to content

Commit 237eee5

Browse files
author
Andrei Neagu
committed
revert adapter pattern
1 parent 79dc0e1 commit 237eee5

File tree

5 files changed

+15
-39
lines changed

5 files changed

+15
-39
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# mypy: disable-error-code=truthy-function
2-
from typing import Any, Final, Literal, TypeAlias
2+
from typing import Any, Literal, TypeAlias
33

4-
from pydantic import ConfigDict, Field, TypeAdapter
4+
from pydantic import ConfigDict, Field
55

66
from ..api_schemas_directorv2.dynamic_services import RetrieveDataOut
77
from ..basic_types import PortInt
@@ -127,9 +127,6 @@ class NodeGet(OutputSchema):
127127
)
128128

129129

130-
NodeGetAdapter: Final[TypeAdapter[NodeGet]] = TypeAdapter(NodeGet)
131-
132-
133130
class NodeGetIdle(OutputSchema):
134131
service_state: Literal["idle"]
135132
service_uuid: NodeID
@@ -148,9 +145,6 @@ def from_node_id(cls, node_id: NodeID) -> "NodeGetIdle":
148145
)
149146

150147

151-
NodeGetIdleAdapter: Final[TypeAdapter[NodeGetIdle]] = TypeAdapter(NodeGetIdle)
152-
153-
154148
class NodeGetUnknown(OutputSchema):
155149
service_state: Literal["unknown"]
156150
service_uuid: NodeID

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_public_client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
from models_library.api_schemas_dynamic_scheduler.dynamic_services import (
77
DynamicServiceStart,
88
)
9-
from models_library.api_schemas_webserver.projects_nodes import (
10-
NodeGet,
11-
NodeGetAdapter,
12-
NodeGetIdle,
13-
)
9+
from models_library.api_schemas_webserver.projects_nodes import NodeGet, NodeGetIdle
1410
from models_library.projects_nodes_io import NodeID
1511
from pydantic import TypeAdapter
1612
from servicelib.fastapi.app_state import SingletonInAppStateMixin
@@ -48,7 +44,7 @@ async def get_status(
4844
# in case of legacy version
4945
# we need to transfer the correct format!
5046
if "data" in dict_response:
51-
return NodeGetAdapter.validate_python(dict_response["data"])
47+
return TypeAdapter(NodeGet).validate_python(dict_response["data"])
5248

5349
return TypeAdapter(DynamicServiceGet).validate_python(dict_response)
5450
except UnexpectedStatusError as e:
@@ -67,7 +63,7 @@ async def run_dynamic_service(
6763

6864
# legacy services
6965
if "data" in dict_response:
70-
return NodeGetAdapter.validate_python(dict_response["data"])
66+
return TypeAdapter(NodeGet).validate_python(dict_response["data"])
7167

7268
return TypeAdapter(DynamicServiceGet).validate_python(dict_response)
7369

services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
DynamicServiceStart,
1515
DynamicServiceStop,
1616
)
17-
from models_library.api_schemas_webserver.projects_nodes import (
18-
NodeGet,
19-
NodeGetAdapter,
20-
NodeGetIdle,
21-
)
17+
from models_library.api_schemas_webserver.projects_nodes import NodeGet, NodeGetIdle
2218
from models_library.projects import ProjectID
2319
from models_library.projects_nodes_io import NodeID
2420
from models_library.users import UserID
@@ -64,7 +60,7 @@ def service_status_new_style() -> DynamicServiceGet:
6460

6561
@pytest.fixture
6662
def service_status_legacy() -> NodeGet:
67-
return NodeGetAdapter.validate_python(
63+
return TypeAdapter(NodeGet).validate_python(
6864
NodeGet.model_config["json_schema_extra"]["examples"][1]
6965
)
7066

services/dynamic-scheduler/tests/unit/service_tracker/test__api.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414
DynamicServiceStart,
1515
DynamicServiceStop,
1616
)
17-
from models_library.api_schemas_webserver.projects_nodes import (
18-
NodeGet,
19-
NodeGetAdapter,
20-
NodeGetIdle,
21-
NodeGetIdleAdapter,
22-
)
17+
from models_library.api_schemas_webserver.projects_nodes import NodeGet, NodeGetIdle
2318
from models_library.projects_nodes_io import NodeID
2419
from models_library.services_enums import ServiceState
2520
from pydantic import NonNegativeInt, TypeAdapter
@@ -172,7 +167,7 @@ async def test_set_service_status_task_uid(
172167
"status, expected_poll_interval",
173168
[
174169
(
175-
NodeGetAdapter.validate_python(
170+
TypeAdapter(NodeGet).validate_python(
176171
NodeGet.model_config["json_schema_extra"]["examples"][1]
177172
),
178173
_LOW_RATE_POLL_INTERVAL,
@@ -185,7 +180,7 @@ async def test_set_service_status_task_uid(
185180
for o in DynamicServiceGet.model_config["json_schema_extra"]["examples"]
186181
],
187182
(
188-
NodeGetIdleAdapter.validate_python(
183+
TypeAdapter(NodeGetIdle).validate_python(
189184
NodeGetIdle.model_config["json_schema_extra"]["example"]
190185
),
191186
_LOW_RATE_POLL_INTERVAL,
@@ -202,7 +197,7 @@ def _get_node_get_from(service_state: ServiceState) -> NodeGet:
202197
dict_data = NodeGet.model_config["json_schema_extra"]["examples"][1]
203198
assert "service_state" in dict_data
204199
dict_data["service_state"] = service_state
205-
return NodeGetAdapter.validate_python(dict_data)
200+
return TypeAdapter(NodeGet).validate_python(dict_data)
206201

207202

208203
def _get_dynamic_service_get_from(
@@ -215,7 +210,7 @@ def _get_dynamic_service_get_from(
215210

216211

217212
def _get_node_get_idle() -> NodeGetIdle:
218-
return NodeGetIdleAdapter.validate_python(
213+
return TypeAdapter(NodeGetIdle).validate_python(
219214
NodeGetIdle.model_config["json_schema_extra"]["example"]
220215
)
221216

services/dynamic-scheduler/tests/unit/status_monitor/test_services_status_monitor__monitor.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
DynamicServiceStart,
2121
DynamicServiceStop,
2222
)
23-
from models_library.api_schemas_webserver.projects_nodes import (
24-
NodeGet,
25-
NodeGetAdapter,
26-
NodeGetIdle,
27-
NodeGetIdleAdapter,
28-
)
23+
from models_library.api_schemas_webserver.projects_nodes import NodeGet, NodeGetIdle
2924
from models_library.projects_nodes_io import NodeID
3025
from pydantic import NonNegativeInt, TypeAdapter
3126
from pytest_mock import MockerFixture
@@ -82,7 +77,7 @@ def _get_node_get_with(state: str, node_id: NodeID = _DEFAULT_NODE_ID) -> NodeGe
8277
("service_uuid", f"{node_id}"),
8378
],
8479
)
85-
return NodeGetAdapter.validate_python(dict_data)
80+
return TypeAdapter(NodeGet).validate_python(dict_data)
8681

8782

8883
def _get_dynamic_service_get_legacy_with(
@@ -127,7 +122,7 @@ def _get_node_get_idle(node_id: NodeID = _DEFAULT_NODE_ID) -> NodeGetIdle:
127122
("service_uuid", f"{node_id}"),
128123
],
129124
)
130-
return NodeGetIdleAdapter.validate_python(dict_data)
125+
return TypeAdapter(NodeGetIdle).validate_python(dict_data)
131126

132127

133128
class _ResponseTimeline:

0 commit comments

Comments
 (0)