Skip to content

Commit

Permalink
removed occurences of parse_obj_as
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Nov 1, 2024
1 parent 5b84329 commit 233da09
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/postgres-database/tests/test_utils_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
)
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"],
Expand All @@ -38,5 +38,5 @@ def cluster_information_from_docker_nodes(
},
}
for node in nodes_list
},
}
)

0 comments on commit 233da09

Please sign in to comment.