diff --git a/packages/postgres-database/tests/test_utils_projects.py b/packages/postgres-database/tests/test_utils_projects.py index 9af318fca38..c0c00d271e6 100644 --- a/packages/postgres-database/tests/test_utils_projects.py +++ b/packages/postgres-database/tests/test_utils_projects.py @@ -12,7 +12,7 @@ from aiopg.sa.connection import SAConnection from aiopg.sa.result import RowProxy from faker import Faker -from pydantic import parse_obj_as +from pydantic import TypeAdapter from simcore_postgres_database.models.projects import projects from simcore_postgres_database.utils_projects import ( DBProjectNotFoundError, @@ -69,7 +69,7 @@ async def test_get_project_trashed_at_column_can_be_converted_to_datetime( row = result.fetchone() - trashed_at = parse_obj_as(datetime | None, row.trashed_at) + trashed_at = TypeAdapter(datetime | None).validate_python(row.trashed_at) assert trashed_at == expected diff --git a/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/agent/volumes.py b/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/agent/volumes.py index d414cd6b979..043898dcb30 100644 --- a/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/agent/volumes.py +++ b/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/agent/volumes.py @@ -4,7 +4,7 @@ from models_library.projects_nodes_io import NodeID from models_library.rabbitmq_basic_types import RPCMethodName, RPCNamespace -from pydantic import NonNegativeInt, parse_obj_as +from pydantic import NonNegativeInt, TypeAdapter from servicelib.logging_utils import log_decorator from servicelib.rabbitmq import RabbitMQRPCClient @@ -29,7 +29,9 @@ async def remove_volumes_without_backup_for_service( "swarm_stack_name": swarm_stack_name, } ), - parse_obj_as(RPCMethodName, "remove_volumes_without_backup_for_service"), + TypeAdapter(RPCMethodName).validate_python( + "remove_volumes_without_backup_for_service" + ), node_id=node_id, timeout_s=_REQUEST_TIMEOUT, ) @@ -51,7 +53,9 @@ async def backup_and_remove_volumes_for_all_services( "swarm_stack_name": swarm_stack_name, } ), - parse_obj_as(RPCMethodName, "backup_and_remove_volumes_for_all_services"), + TypeAdapter(RPCMethodName).validate_python( + "backup_and_remove_volumes_for_all_services" + ), timeout_s=_REQUEST_TIMEOUT, ) assert result is None # nosec diff --git a/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/disk_usage.py b/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/disk_usage.py index 5938ad871ff..dbace2f1f4b 100644 --- a/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/disk_usage.py +++ b/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/disk_usage.py @@ -1,14 +1,20 @@ import logging +from typing import Final from models_library.api_schemas_dynamic_sidecar.telemetry import DiskUsage from models_library.projects_nodes_io import NodeID from models_library.rabbitmq_basic_types import RPCMethodName, RPCNamespace -from pydantic import parse_obj_as -from servicelib.logging_utils import log_decorator -from servicelib.rabbitmq import RabbitMQRPCClient +from pydantic import TypeAdapter + +from ....logging_utils import log_decorator +from ... import RabbitMQRPCClient _logger = logging.getLogger(__name__) +_UPDATE_DISK_USAGE: Final[RPCMethodName] = TypeAdapter(RPCMethodName).validate_python( + "update_disk_usage" +) + @log_decorator(_logger, level=logging.DEBUG) async def update_disk_usage( @@ -21,6 +27,8 @@ async def update_disk_usage( {"service": "dy-sidecar", "node_id": f"{node_id}"} ) result = await rabbitmq_rpc_client.request( - rpc_namespace, parse_obj_as(RPCMethodName, "update_disk_usage"), usage=usage + rpc_namespace, + _UPDATE_DISK_USAGE, + usage=usage, ) assert result is None # nosec diff --git a/services/osparc-gateway-server/src/osparc_gateway_server/backend/models.py b/services/osparc-gateway-server/src/osparc_gateway_server/backend/models.py index 43e2240270d..9cdd2fc9edb 100644 --- a/services/osparc-gateway-server/src/osparc_gateway_server/backend/models.py +++ b/services/osparc-gateway-server/src/osparc_gateway_server/backend/models.py @@ -1,7 +1,8 @@ +from collections.abc import Mapping from ipaddress import IPv4Address -from typing import Any, Mapping, Union +from typing import Any, Union -from pydantic import BaseModel, ByteSize, Field, PositiveFloat, parse_obj_as +from pydantic import BaseModel, ByteSize, Field, PositiveFloat, TypeAdapter Hostname = str ResourceName = str @@ -26,8 +27,7 @@ class NodeInformation(BaseModel): def cluster_information_from_docker_nodes( nodes_list: list[Mapping[str, Any]] ) -> ClusterInformation: - return parse_obj_as( - ClusterInformation, + return TypeAdapter(ClusterInformation).validate_python( { node["Description"]["Hostname"]: { "docker_node_id": node["ID"], @@ -38,5 +38,5 @@ def cluster_information_from_docker_nodes( }, } for node in nodes_list - }, + } )