File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
services/director-v2/src/simcore_service_director_v2
modules/db/repositories/comp_tasks Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -276,3 +276,15 @@ class ComputationTaskForRpcDBGet(BaseModel):
276276 image : dict [str , Any ]
277277 started_at : dt .datetime | None
278278 ended_at : dt .datetime | None
279+
280+ @field_validator ("state" , mode = "before" )
281+ @classmethod
282+ def _convert_from_state_type_enum_if_needed (cls , v ):
283+ if isinstance (v , str ):
284+ # try to convert to a StateType, if it fails the validations will continue
285+ # and pydantic will try to convert it to a RunninState later on
286+ with suppress (ValueError ):
287+ v = StateType (v )
288+ if isinstance (v , StateType ):
289+ return RunningState (DB_TO_RUNNING_STATE [v ])
290+ return v
Original file line number Diff line number Diff line change 2323from .....models .comp_tasks import CompTaskAtDB , ComputationTaskForRpcDBGet
2424from .....modules .resource_usage_tracker_client import ResourceUsageTrackerClient
2525from .....utils .computations import to_node_class
26- from .....utils .db import DB_TO_RUNNING_STATE , RUNNING_STATE_TO_DB
26+ from .....utils .db import RUNNING_STATE_TO_DB
2727from ....catalog import CatalogClient
2828from ...tables import NodeClass , StateType , comp_run_snapshot_tasks , comp_tasks
2929from .._base import BaseRepository
@@ -130,12 +130,7 @@ async def list_computational_tasks_rpc_domain(
130130 total_count = await conn .scalar (count_query )
131131
132132 items = [
133- ComputationTaskForRpcDBGet .model_validate (
134- {
135- ** row ,
136- "state" : DB_TO_RUNNING_STATE [row ["state" ]], # Convert the state
137- }
138- )
133+ ComputationTaskForRpcDBGet .model_validate (row , from_attributes = True )
139134 async for row in await conn .stream (list_query )
140135 ]
141136 return cast (int , total_count ), items
You can’t perform that action at this time.
0 commit comments