Skip to content

Commit 00370e5

Browse files
fix: create_node fixture
1 parent 764a386 commit 00370e5

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from models_library.users import UserID
1515
from pydantic import TypeAdapter
1616
from simcore_postgres_database.models.project_to_groups import project_to_groups
17+
from simcore_postgres_database.models.projects_nodes import projects_nodes
1718
from simcore_postgres_database.storage_models import projects, users
1819
from sqlalchemy.dialects.postgresql import insert as pg_insert
1920
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine
@@ -219,26 +220,19 @@ async def _creator(
219220
project_id: ProjectID, node_id: NodeID | None = None, **kwargs
220221
) -> NodeID:
221222
async with sqlalchemy_async_engine.begin() as conn:
222-
result = await conn.execute(
223-
sa.select(projects.c.workbench).where(
224-
projects.c.uuid == f"{project_id}"
225-
)
226-
)
227-
row = result.fetchone()
228-
assert row
229-
project_workbench: dict[str, Any] = row.workbench
230-
new_node_id = node_id or NodeID(f"{faker.uuid4()}")
231-
node_data = {
223+
new_node_id = node_id or NodeID(faker.uuid4())
224+
node_values = {
232225
"key": "simcore/services/frontend/file-picker",
233226
"version": "1.0.0",
234227
"label": "pytest_fake_node",
235228
}
236-
node_data.update(**kwargs)
237-
project_workbench.update({f"{new_node_id}": node_data})
229+
node_values.update(**kwargs)
238230
await conn.execute(
239-
projects.update()
240-
.where(projects.c.uuid == f"{project_id}")
241-
.values(workbench=project_workbench)
231+
projects_nodes.insert().values(
232+
node_id=f"{new_node_id}",
233+
project_uuid=f"{project_id}",
234+
**node_values,
235+
)
242236
)
243237
return new_node_id
244238

services/storage/src/simcore_service_storage/modules/db/projects.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from models_library.projects import ProjectAtDB, ProjectID, ProjectIDStr
66
from models_library.projects_nodes_io import NodeIDStr
77
from pydantic import ValidationError
8+
from simcore_postgres_database.models.projects_nodes import projects_nodes
89
from simcore_postgres_database.storage_models import projects
910
from simcore_postgres_database.utils_repos import pass_or_acquire_connection
1011
from sqlalchemy.ext.asyncio import AsyncConnection
@@ -54,16 +55,28 @@ async def get_project_id_and_node_id_to_names_map(
5455
connection: AsyncConnection | None = None,
5556
project_uuids: list[ProjectID],
5657
) -> dict[ProjectID, dict[ProjectIDStr | NodeIDStr, str]]:
57-
mapping = {}
58+
names_map = {}
5859
async with pass_or_acquire_connection(self.db_engine, connection) as conn:
5960
async for row in await conn.stream(
60-
sa.select(projects.c.uuid, projects.c.name, projects.c.workbench).where(
61-
projects.c.uuid.in_(f"{pid}" for pid in project_uuids)
61+
sa.select(projects.c.uuid, projects.c.name).where(
62+
projects.c.uuid.in_(
63+
[f"{project_uuid}" for project_uuid in project_uuids]
64+
)
6265
)
6366
):
64-
mapping[ProjectID(f"{row.uuid}")] = {f"{row.uuid}": row.name} | {
65-
f"{node_id}": node["label"]
66-
for node_id, node in row.workbench.items()
67-
}
67+
names_map[ProjectID(row.uuid)] = {f"{row.uuid}": row.name}
6868

69-
return mapping
69+
async for row in await conn.stream(
70+
sa.select(
71+
projects_nodes.c.node_id,
72+
projects_nodes.c.project_uuid,
73+
projects_nodes.c.label,
74+
).where(
75+
projects_nodes.c.project_uuid.in_(
76+
[f"{project_uuid}" for project_uuid in project_uuids]
77+
)
78+
)
79+
):
80+
names_map[ProjectID(row.project_uuid)] |= {f"{row.node_id}": row.label}
81+
82+
return names_map

0 commit comments

Comments
 (0)