Skip to content

Commit 8eac56b

Browse files
♻️ Fix deprecated stuff (Pydantic v2) (#6732)
1 parent 84c4c85 commit 8eac56b

File tree

35 files changed

+67
-73
lines changed

35 files changed

+67
-73
lines changed

api/specs/web-server/_common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Any, ClassVar, NamedTuple
99

1010
import yaml
11+
from common_library.pydantic_fields_extension import get_type
1112
from fastapi import FastAPI
1213
from models_library.basic_types import LogLevel
1314
from pydantic import BaseModel, Field
@@ -116,8 +117,8 @@ def assert_handler_signature_against_model(
116117

117118
# query and path parameters
118119
implemented_params = [
119-
ParamSpec(field.name, field.type_, field.field_info)
120-
for field in model_cls.__fields__.values()
120+
ParamSpec(name, get_type(info), info)
121+
for name, info in model_cls.model_fields.items()
121122
]
122123

123124
assert {p.name for p in implemented_params}.issubset( # nosec

packages/models-library/src/models_library/function_services_catalog/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
def iter_service_docker_data() -> Iterator[ServiceMetaDataPublished]:
2525
for meta_obj in catalog.iter_metadata():
2626
# NOTE: the originals are this way not modified from outside
27-
copied_meta_obj = meta_obj.copy(deep=True)
27+
copied_meta_obj = meta_obj.model_copy(deep=True)
2828
assert is_function_service(copied_meta_obj.key) # nosec
2929
yield copied_meta_obj
3030

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def create_computation_cb(url, **kwargs) -> CallbackResult:
109109
}
110110
returned_computation = ComputationTask.model_validate(
111111
ComputationTask.model_config["json_schema_extra"]["examples"][0]
112-
).copy(
112+
).model_copy(
113113
update={
114114
"id": f"{kwargs['json']['project_id']}",
115115
"state": state,
@@ -133,7 +133,7 @@ def get_computation_cb(url, **kwargs) -> CallbackResult:
133133
node_states = FULL_PROJECT_NODE_STATES
134134
returned_computation = ComputationTask.model_validate(
135135
ComputationTask.model_config["json_schema_extra"]["examples"][0]
136-
).copy(
136+
).model_copy(
137137
update={
138138
"id": Path(url.path).name,
139139
"state": state,

packages/service-library/src/servicelib/aiohttp/db_asyncpg_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async def connect_to_db(app: web.Application, settings: PostgresSettings) -> Non
4646
- sets an engine in app state (use `get_async_engine(app)` to retrieve)
4747
"""
4848
if settings.POSTGRES_CLIENT_NAME:
49-
settings = settings.copy(
49+
settings = settings.model_copy(
5050
update={"POSTGRES_CLIENT_NAME": settings.POSTGRES_CLIENT_NAME + "-asyncpg"}
5151
)
5252

packages/service-library/src/servicelib/aiohttp/requests_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def parse_request_query_parameters_as(
171171
# query parameters with the same key. However, we are not using such cases anywhere at the moment.
172172
data = dict(request.query)
173173

174-
if hasattr(parameters_schema_cls, "parse_obj"):
174+
if hasattr(parameters_schema_cls, "model_validate"):
175175
return parameters_schema_cls.model_validate(data)
176176
model: ModelClass = TypeAdapter(parameters_schema_cls).validate_python(data)
177177
return model

packages/service-library/src/servicelib/project_lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def lock_project(
4949
value=True,
5050
owner=owner,
5151
status=status,
52-
).json(),
52+
).model_dump_json(),
5353
):
5454
msg = f"Lock for project {project_uuid!r} owner {owner!r} could not be acquired"
5555
raise ProjectLockError(msg)

packages/service-library/src/servicelib/services_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_status_as_dict(
2222
) -> dict:
2323
"""shared between different backend services to guarantee same result to frontend"""
2424
return (
25-
status.dict(by_alias=True)
25+
status.model_dump(by_alias=True)
2626
if isinstance(status, DynamicServiceGet)
27-
else status.dict()
27+
else status.model_dump()
2828
)

packages/service-library/tests/aiohttp/long_running_tasks/test_long_running_tasks_with_task_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def _test_task_context_decorator(
5353
) -> web.StreamResponse:
5454
"""this task context callback tries to get the user_id from the query if available"""
5555
query_param = parse_request_query_parameters_as(query_model, request)
56-
request[RQT_LONG_RUNNING_TASKS_CONTEXT_KEY] = query_param.dict()
56+
request[RQT_LONG_RUNNING_TASKS_CONTEXT_KEY] = query_param.model_dump()
5757
return await handler(request)
5858

5959
return _test_task_context_decorator

packages/settings-library/src/settings_library/utils_encoders.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

services/agent/tests/unit/test_api_rest__health.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
def test_health_ok(test_client: TestClient):
1515
response = test_client.get("/health")
1616
assert response.status_code == status.HTTP_200_OK
17-
assert HealthCheckGet.parse_obj(response.json())
17+
assert HealthCheckGet.model_validate(response.json())

0 commit comments

Comments
 (0)