Skip to content

Commit c0d7560

Browse files
fix bug
1 parent 0480725 commit c0d7560

File tree

5 files changed

+267
-6
lines changed

5 files changed

+267
-6
lines changed

api/specs/web-server/_computations.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from models_library.api_schemas_webserver.computations import (
77
ComputationCollectionRunListQueryParams,
88
ComputationCollectionRunPathParams,
9+
ComputationCollectionRunRestGet,
910
ComputationCollectionRunTaskListQueryParams,
11+
ComputationCollectionRunTaskRestGet,
1012
ComputationGet,
1113
ComputationPathParams,
1214
ComputationRunIterationsLatestListQueryParams,
@@ -102,7 +104,7 @@ async def list_computations_latest_iteration_tasks(
102104

103105
@router.get(
104106
"/computation-collection-runs",
105-
response_model=Page[ComputationTaskRestGet],
107+
response_model=Page[ComputationCollectionRunRestGet],
106108
)
107109
async def list_computation_collection_runs(
108110
_query: Annotated[as_query(ComputationCollectionRunListQueryParams), Depends()],
@@ -111,7 +113,7 @@ async def list_computation_collection_runs(
111113

112114
@router.get(
113115
"/computation-collection-runs/{collection_run_id}/tasks",
114-
response_model=Page[ComputationTaskRestGet],
116+
response_model=Page[ComputationCollectionRunTaskRestGet],
115117
)
116118
async def list_computation_collection_run_tasks(
117119
_query: Annotated[as_query(ComputationCollectionRunTaskListQueryParams), Depends()],

services/director-v2/src/simcore_service_director_v2/api/rpc/_computations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ async def list_computation_collection_runs_page(
114114
collection_run_ids = await comp_runs_repo.list_all_collection_run_ids_for_user_currently_running_computations(
115115
product_name=product_name, user_id=user_id
116116
)
117+
if collection_run_ids == []:
118+
return ComputationCollectionRunRpcGetPage(items=[], total=0)
117119

118120
total, comp_runs_output = await comp_runs_repo.list_group_by_collection_run_id(
119121
product_name=product_name,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,13 @@ async def list_group_by_collection_run_id(
442442
& (comp_runs.c.metadata["product_name"].astext == product_name)
443443
)
444444

445-
if project_ids_or_none:
445+
if project_ids_or_none is not None:
446446
base_select_query = base_select_query.where(
447447
comp_runs.c.project_uuid.in_(
448448
[f"{project_id}" for project_id in project_ids_or_none]
449449
)
450450
)
451-
if collection_run_ids_or_none:
451+
if collection_run_ids_or_none is not None:
452452
base_select_query = base_select_query.where(
453453
comp_runs.c.collection_run_id.in_(
454454
[

services/director-v2/tests/unit/with_dbs/comp_scheduler/test_api_rpc_computations.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,82 @@ async def test_rpc_list_computation_collection_runs_page_and_collection_run_task
341341
assert len(output.items) == 1
342342
assert isinstance(output, ComputationCollectionRunRpcGetPage)
343343
assert len(output.items[0].project_ids) == 2
344+
345+
346+
async def test_rpc_list_computation_collection_runs_empty_ids_when_user_has_already_run_history(
347+
fake_workbench_without_outputs: dict[str, Any], # <-- Has 4 nodes
348+
fake_workbench_adjacency: dict[str, Any],
349+
create_registered_user: Callable[..., dict[str, Any]],
350+
create_project: Callable[..., Awaitable[ProjectAtDB]],
351+
create_pipeline: Callable[..., Awaitable[CompPipelineAtDB]],
352+
create_tasks_from_project: Callable[..., Awaitable[list[CompTaskAtDB]]],
353+
create_comp_run_snapshot_tasks: Callable[
354+
..., Awaitable[list[CompRunSnapshotTaskDBGet]]
355+
],
356+
create_comp_run: Callable[..., Awaitable[CompRunsAtDB]],
357+
rpc_client: RabbitMQRPCClient,
358+
faker: Faker,
359+
with_product: dict[str, Any],
360+
):
361+
user = create_registered_user()
362+
proj = await create_project(user, workbench=fake_workbench_without_outputs)
363+
364+
await create_pipeline(
365+
project_id=f"{proj.uuid}",
366+
dag_adjacency_list=fake_workbench_adjacency,
367+
)
368+
await create_tasks_from_project(
369+
user=user, project=proj, state=RunningState.SUCCESS, progress=None
370+
)
371+
run = await create_comp_run(
372+
user=user,
373+
project=proj,
374+
result=RunningState.SUCCESS,
375+
started=datetime.now(tz=UTC) - timedelta(minutes=120),
376+
ended=datetime.now(tz=UTC) - timedelta(minutes=100),
377+
iteration=1,
378+
dag_adjacency_list=fake_workbench_adjacency,
379+
)
380+
await create_comp_run_snapshot_tasks(
381+
user=user,
382+
project=proj,
383+
run_id=run.run_id,
384+
)
385+
386+
output = await rpc_computations.list_computation_collection_runs_page(
387+
rpc_client, product_name="osparc", user_id=user["id"], project_ids=None
388+
)
389+
assert output.total == 1
390+
assert len(output.items) == 1
391+
assert isinstance(output, ComputationCollectionRunRpcGetPage)
392+
393+
# Test filtering only running collection runs
394+
output = await rpc_computations.list_computation_collection_runs_page(
395+
rpc_client,
396+
product_name="osparc",
397+
user_id=user["id"],
398+
project_ids=None,
399+
filter_only_running=True, # <-- This is the tested filter
400+
)
401+
assert output.total == 0
402+
assert len(output.items) == 0
403+
404+
405+
async def test_rpc_list_computation_collection_runs_empty_ids_when_user_do_not_have_run_history(
406+
create_registered_user: Callable[..., dict[str, Any]],
407+
rpc_client: RabbitMQRPCClient,
408+
with_product: dict[str, Any],
409+
):
410+
user = create_registered_user()
411+
412+
# Test with empty collection_run_ids
413+
output = await rpc_computations.list_computation_collection_runs_page(
414+
rpc_client,
415+
product_name="osparc",
416+
user_id=user["id"],
417+
project_ids=None,
418+
filter_only_running=True, # This will result in empty collection_run_ids
419+
)
420+
assert output.total == 0
421+
assert len(output.items) == 0
422+
assert isinstance(output, ComputationCollectionRunRpcGetPage)

services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

Lines changed: 180 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,7 @@ paths:
28202820
content:
28212821
application/json:
28222822
schema:
2823-
$ref: '#/components/schemas/Page_ComputationTaskRestGet_'
2823+
$ref: '#/components/schemas/Page_ComputationCollectionRunRestGet_'
28242824
/v0/computation-collection-runs/{collection_run_id}/tasks:
28252825
get:
28262826
tags:
@@ -2856,7 +2856,7 @@ paths:
28562856
content:
28572857
application/json:
28582858
schema:
2859-
$ref: '#/components/schemas/Page_ComputationTaskRestGet_'
2859+
$ref: '#/components/schemas/Page_ComputationCollectionRunTaskRestGet_'
28602860
/v0/projects/{project_id}:xport:
28612861
post:
28622862
tags:
@@ -9357,6 +9357,108 @@ components:
93579357
required:
93589358
- version
93599359
title: CompatibleService
9360+
ComputationCollectionRunRestGet:
9361+
properties:
9362+
collectionRunId:
9363+
type: string
9364+
format: uuid
9365+
title: Collectionrunid
9366+
projectIds:
9367+
items:
9368+
type: string
9369+
type: array
9370+
title: Projectids
9371+
state:
9372+
$ref: '#/components/schemas/RunningState'
9373+
info:
9374+
type: object
9375+
title: Info
9376+
submittedAt:
9377+
type: string
9378+
format: date-time
9379+
title: Submittedat
9380+
startedAt:
9381+
anyOf:
9382+
- type: string
9383+
format: date-time
9384+
- type: 'null'
9385+
title: Startedat
9386+
endedAt:
9387+
anyOf:
9388+
- type: string
9389+
format: date-time
9390+
- type: 'null'
9391+
title: Endedat
9392+
name:
9393+
type: string
9394+
title: Name
9395+
type: object
9396+
required:
9397+
- collectionRunId
9398+
- projectIds
9399+
- state
9400+
- info
9401+
- submittedAt
9402+
- startedAt
9403+
- endedAt
9404+
- name
9405+
title: ComputationCollectionRunRestGet
9406+
ComputationCollectionRunTaskRestGet:
9407+
properties:
9408+
projectUuid:
9409+
type: string
9410+
format: uuid
9411+
title: Projectuuid
9412+
nodeId:
9413+
type: string
9414+
format: uuid
9415+
title: Nodeid
9416+
state:
9417+
$ref: '#/components/schemas/RunningState'
9418+
progress:
9419+
type: number
9420+
title: Progress
9421+
image:
9422+
type: object
9423+
title: Image
9424+
startedAt:
9425+
anyOf:
9426+
- type: string
9427+
format: date-time
9428+
- type: 'null'
9429+
title: Startedat
9430+
endedAt:
9431+
anyOf:
9432+
- type: string
9433+
format: date-time
9434+
- type: 'null'
9435+
title: Endedat
9436+
logDownloadLink:
9437+
anyOf:
9438+
- type: string
9439+
- type: 'null'
9440+
title: Logdownloadlink
9441+
osparcCredits:
9442+
anyOf:
9443+
- type: string
9444+
- type: 'null'
9445+
title: Osparccredits
9446+
name:
9447+
type: string
9448+
title: Name
9449+
type: object
9450+
required:
9451+
- projectUuid
9452+
- nodeId
9453+
- state
9454+
- progress
9455+
- image
9456+
- startedAt
9457+
- endedAt
9458+
- logDownloadLink
9459+
- osparcCredits
9460+
- name
9461+
title: ComputationCollectionRunTaskRestGet
93609462
ComputationGet:
93619463
properties:
93629464
id:
@@ -13762,6 +13864,82 @@ components:
1376213864
- _links
1376313865
- data
1376413866
title: Page[CatalogLatestServiceGet]
13867+
Page_ComputationCollectionRunRestGet_:
13868+
properties:
13869+
items:
13870+
items:
13871+
$ref: '#/components/schemas/ComputationCollectionRunRestGet'
13872+
type: array
13873+
title: Items
13874+
total:
13875+
anyOf:
13876+
- type: integer
13877+
minimum: 0
13878+
- type: 'null'
13879+
title: Total
13880+
page:
13881+
anyOf:
13882+
- type: integer
13883+
minimum: 1
13884+
- type: 'null'
13885+
title: Page
13886+
size:
13887+
anyOf:
13888+
- type: integer
13889+
minimum: 1
13890+
- type: 'null'
13891+
title: Size
13892+
pages:
13893+
anyOf:
13894+
- type: integer
13895+
minimum: 0
13896+
- type: 'null'
13897+
title: Pages
13898+
type: object
13899+
required:
13900+
- items
13901+
- total
13902+
- page
13903+
- size
13904+
title: Page[ComputationCollectionRunRestGet]
13905+
Page_ComputationCollectionRunTaskRestGet_:
13906+
properties:
13907+
items:
13908+
items:
13909+
$ref: '#/components/schemas/ComputationCollectionRunTaskRestGet'
13910+
type: array
13911+
title: Items
13912+
total:
13913+
anyOf:
13914+
- type: integer
13915+
minimum: 0
13916+
- type: 'null'
13917+
title: Total
13918+
page:
13919+
anyOf:
13920+
- type: integer
13921+
minimum: 1
13922+
- type: 'null'
13923+
title: Page
13924+
size:
13925+
anyOf:
13926+
- type: integer
13927+
minimum: 1
13928+
- type: 'null'
13929+
title: Size
13930+
pages:
13931+
anyOf:
13932+
- type: integer
13933+
minimum: 0
13934+
- type: 'null'
13935+
title: Pages
13936+
type: object
13937+
required:
13938+
- items
13939+
- total
13940+
- page
13941+
- size
13942+
title: Page[ComputationCollectionRunTaskRestGet]
1376513943
Page_ComputationRunRestGet_:
1376613944
properties:
1376713945
items:

0 commit comments

Comments
 (0)