Skip to content

Commit 6c230c6

Browse files
committed
maybe awaiting
1 parent 43d58aa commit 6c230c6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/postgres-database/src/simcore_postgres_database/utils_projects_metadata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any
44

55
import sqlalchemy as sa
6+
from common_library.async_tools import maybe_await
67
from common_library.errors_classes import OsparcErrorMixin
78
from pydantic import BaseModel, ConfigDict
89
from sqlalchemy.dialects.postgresql import insert as pg_insert
@@ -93,7 +94,7 @@ async def get(connection: DBConnection, project_uuid: uuid.UUID) -> ProjectMetad
9394
.where(projects.c.uuid == f"{project_uuid}")
9495
)
9596
result = await connection.execute(get_stmt)
96-
row = await result.first()
97+
row = await maybe_await(result.first())
9798
if row is None:
9899
raise DBProjectNotFoundError(project_uuid=project_uuid)
99100
return ProjectMetadata.model_validate(row)
@@ -203,7 +204,7 @@ async def set_project_ancestors(
203204

204205
try:
205206
result = await connection.execute(upsert_stmt)
206-
row = await result.first()
207+
row = await maybe_await(result.first())
207208
assert row # nosec
208209
return ProjectMetadata.model_validate(row)
209210

services/director-v2/src/simcore_service_director_v2/models/comp_tasks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,18 @@ def _backward_compatible_null_value(cls, v: HardwareInfo | None) -> HardwareInfo
181181
return v
182182

183183
def to_db_model(self, **exclusion_rules) -> dict[str, Any]:
184+
# mode json is used to ensure the UUIDs are converted to strings
184185
comp_task_dict = self.model_dump(
185186
mode="json", by_alias=True, exclude_unset=True, **exclusion_rules
186187
)
188+
# Convert state to DB enum value
187189
if "state" in comp_task_dict:
188190
comp_task_dict["state"] = RUNNING_STATE_TO_DB[comp_task_dict["state"]].value
191+
# but now the datetimes are strings which are not compatible with the DB
192+
# so we need to convert them back to datetime objects
193+
for field in ["start", "end", "last_heartbeat", "created", "modified"]:
194+
if field in comp_task_dict and isinstance(comp_task_dict[field], str):
195+
comp_task_dict[field] = dt.datetime.fromisoformat(comp_task_dict[field])
189196
return comp_task_dict
190197

191198
model_config = ConfigDict(

0 commit comments

Comments
 (0)