Skip to content

Commit ee061d4

Browse files
add first batch of unit tests
1 parent 44767c0 commit ee061d4

File tree

7 files changed

+748
-17
lines changed

7 files changed

+748
-17
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""computational collection runs
22
3-
Revision ID: 5baec57326b3
3+
Revision ID: 42ec7816c0b4
44
Revises: 4f6fd2586491
5-
Create Date: 2025-07-01 12:20:10.464764+00:00
5+
Create Date: 2025-07-01 13:30:02.736058+00:00
66
77
"""
88

@@ -11,7 +11,7 @@
1111
from sqlalchemy.dialects import postgresql
1212

1313
# revision identifiers, used by Alembic.
14-
revision = "5baec57326b3"
14+
revision = "42ec7816c0b4"
1515
down_revision = "4f6fd2586491"
1616
branch_labels = None
1717
depends_on = None
@@ -21,7 +21,12 @@ def upgrade():
2121
# ### commands auto generated by Alembic - please adjust! ###
2222
op.create_table(
2323
"comp_run_collections",
24-
sa.Column("collection_run_id", postgresql.UUID(as_uuid=True), nullable=False),
24+
sa.Column(
25+
"collection_run_id",
26+
postgresql.UUID(as_uuid=True),
27+
server_default=sa.text("gen_random_uuid()"),
28+
nullable=False,
29+
),
2530
sa.Column("client_or_system_generated_id", sa.String(), nullable=False),
2631
sa.Column(
2732
"client_or_system_generated_display_name", sa.String(), nullable=False
@@ -48,7 +53,7 @@ def upgrade():
4853
unique=False,
4954
)
5055
op.add_column(
51-
"comp_runs", sa.Column("collection_run_id", sa.String(), nullable=True)
56+
"comp_runs", sa.Column("collection_run_id", sa.String(), nullable=False)
5257
)
5358

5459
# Data migration: Create collection run records for existing comp_runs

packages/postgres-database/src/simcore_postgres_database/models/comp_run_collections.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
sa.Column(
1313
"collection_run_id",
1414
UUID(as_uuid=True),
15+
server_default=sa.text("gen_random_uuid()"),
1516
nullable=False,
1617
primary_key=True,
1718
),

services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_runs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ async def list_group_by_collection_run_id(
391391
comp_runs.c.collection_run_id,
392392
sa.func.array_agg(comp_runs.c.project_uuid).label("project_ids"),
393393
sa.func.array_agg(comp_runs.c.result).label("states"),
394-
# For simplicity, we use min here:
395-
sa.func.min(comp_runs.c.metadata).label("info"),
394+
# For simplicity, we use any metadata from the collection (first one in aggregation order):
395+
sa.literal_column("(jsonb_agg(comp_runs.metadata))[1]").label("info"),
396396
sa.func.min(comp_runs.c.created).label("submitted_at"),
397397
sa.func.min(comp_runs.c.started).label("started_at"),
398398
sa.func.min(comp_runs.c.run_id).label("min_run_id"),
@@ -416,7 +416,7 @@ async def list_group_by_collection_run_id(
416416
)
417417

418418
base_select_query_with_group_by = base_select_query.group_by(
419-
comp_runs.c.group_by_flag
419+
comp_runs.c.collection_run_id
420420
)
421421

422422
count_query = sa.select(sa.func.count()).select_from(
@@ -441,7 +441,7 @@ async def list_group_by_collection_run_id(
441441
collection_run_id=row["collection_run_id"],
442442
project_ids=row["project_ids"],
443443
state=resolved_state,
444-
info=row["info"],
444+
info={} if row["info"] is None else row["info"],
445445
submitted_at=row["submitted_at"],
446446
started_at=row["started_at"],
447447
ended_at=row["ended_at"],
@@ -475,7 +475,7 @@ async def create(
475475
metadata=jsonable_encoder(metadata),
476476
use_on_demand_clusters=use_on_demand_clusters,
477477
dag_adjacency_list=dag_adjacency_list,
478-
collection_run_id=collection_run_id,
478+
collection_run_id=f"{collection_run_id}",
479479
)
480480
.returning(literal_column("*"))
481481
)

0 commit comments

Comments
 (0)