55import asyncio
66import uuid
77from collections .abc import AsyncIterator , Awaitable , Callable
8+ from typing import Any
89from unittest .mock import AsyncMock
910
1011import httpx
1617from pytest_mock import MockerFixture
1718from pytest_simcore .helpers .typing_env import EnvVarsDict
1819from simcore_postgres_database .models .comp_tasks import comp_tasks
19- from simcore_postgres_database .models .projects import projects
20+ from simcore_postgres_database .models .projects_nodes import projects_nodes
2021from starlette import status
2122from tenacity import retry
2223from tenacity .retry import retry_if_exception_type
@@ -35,31 +36,40 @@ def mock_env(mock_env: EnvVarsDict, minio_s3_settings_envs: EnvVarsDict) -> EnvV
3536def update_project_workbench_with_comp_tasks (
3637 postgres_db : sa .engine .Engine ,
3738) -> Callable :
38- def updator (project_uuid : str ):
39+ def _updator (project_uuid : str ):
3940 with postgres_db .connect () as con :
41+
42+ # select all projects_nodes for this project
4043 result = con .execute (
41- projects .select ().where (projects .c .uuid == project_uuid )
44+ projects_nodes .select ().where (
45+ projects_nodes .c .project_uuid == project_uuid
46+ )
4247 )
43- prj_row = result . first ()
44- assert prj_row
45- prj_workbench = prj_row . workbench
48+ project_nodes_map : dict [ str , Any ] = {
49+ row . node_id : row . _asdict () for row in result
50+ }
4651
52+ # comp_tasks get and run_hash and outputs
4753 result = con .execute (
48- comp_tasks .select ().where (comp_tasks .c .project_id == project_uuid )
49- )
50- # let's get the results and run_hash
51- for task_row in result :
52- # pass these to the project workbench
53- prj_workbench [task_row .node_id ]["outputs" ] = task_row .outputs
54- prj_workbench [task_row .node_id ]["runHash" ] = task_row .run_hash
55-
56- con .execute (
57- projects .update () # pylint:disable=no-value-for-parameter
58- .values (workbench = prj_workbench )
59- .where (projects .c .uuid == project_uuid )
54+ comp_tasks .select ().where (comp_tasks .c .project_id == f"{ project_uuid } " )
6055 )
61-
62- return updator
56+ comp_tasks_rows = result .fetchall ()
57+ for task_row in comp_tasks_rows :
58+ project_nodes_map [task_row .node_id ]["outputs" ] = task_row .outputs
59+ project_nodes_map [task_row .node_id ]["run_hash" ] = task_row .run_hash
60+
61+ # update projects_nodes with comp_tasks data
62+ for node_id , node_data in project_nodes_map .items ():
63+ con .execute (
64+ projects_nodes .update () # pylint:disable=no-value-for-parameter
65+ .values (** node_data )
66+ .where (
67+ (projects_nodes .c .node_id == node_id )
68+ & (projects_nodes .c .project_uuid == project_uuid )
69+ )
70+ )
71+
72+ return _updator
6373
6474
6575@pytest .fixture (scope = "session" )
0 commit comments