Skip to content

Commit

Permalink
Merge pull request #665 from fractal-analytics-platform/591-catch-err…
Browse files Browse the repository at this point in the history
…or-in-workflow-apply-endpoint

workflow-apply error handling
  • Loading branch information
tcompa authored May 4, 2023
2 parents cd33f87 + cfc1a7a commit c73ec18
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
**Note**: Numbers like (\#123) point to closed Pull Requests on the fractal-server repository.

# 1.2.5

* Improve error handling in workflow-apply endpoint (\#665).

# 1.2.4

* Review setup for database URLs, especially to allow using UNIX-socket connections for postgresl (\#657).
Expand Down
6 changes: 5 additions & 1 deletion fractal_server/app/api/v1/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ async def apply_workflow(
f"but {user.cache_dir=}."
),
)

if not input_dataset.resource_list:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="Input dataset has empty resource_list",
)
try:
validate_workflow_compatibility(
workflow=workflow,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_full_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ async def test_failing_workflow_TaskExecutionError(
failing_task: str,
request,
override_settings_factory,
resource_factory,
):

override_settings_factory(
Expand Down Expand Up @@ -252,6 +253,9 @@ async def test_failing_workflow_TaskExecutionError(
project, name="input", type="image", read_only=True
)
input_dataset_id = input_dataset.id
await resource_factory(
path=str(tmp777_path / "input_dir"), dataset=input_dataset
)

# CREATE OUTPUT DATASET AND RESOURCE

Expand Down Expand Up @@ -379,6 +383,7 @@ async def test_failing_workflow_JobExecutionError(
monkey_slurm_user,
relink_python_interpreter,
cfut_jobs_finished,
resource_factory,
):

override_settings_factory(
Expand All @@ -400,6 +405,9 @@ async def test_failing_workflow_JobExecutionError(
project, name="input", type="image", read_only=True
)
input_dataset_id = input_dataset.id
await resource_factory(
path=str(tmp777_path / "input_dir"), dataset=input_dataset
)

# CREATE OUTPUT DATASET AND RESOURCE

Expand Down
51 changes: 50 additions & 1 deletion tests/test_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ async def test_project_apply_failures(
assert res.status_code == 422


async def test_project_apply_missing_cache_dir(
async def test_project_apply_missing_user_attributes(
db,
client,
MockCurrentUser,
Expand Down Expand Up @@ -634,6 +634,16 @@ async def test_project_apply_missing_cache_dir(
assert res.status_code == 422
assert "user.cache_dir=None" in res.json()["detail"]

user.cache_dir = "/tmp"
user.slurm_user = None
await db.merge(user)
await db.commit()

res = await client.post(f"{PREFIX}/apply/", json=payload)
debug(res.json())
assert res.status_code == 422
assert "user.slurm_user=None" in res.json()["detail"]


async def test_create_project(
db,
Expand All @@ -646,3 +656,42 @@ async def test_create_project(
res = await client.post(f"{PREFIX}/", json=empty_payload)
debug(res.json())
assert res.status_code == 422


async def test_no_resources(
MockCurrentUser,
project_factory,
dataset_factory,
workflow_factory,
task_factory,
db,
client,
):
async with MockCurrentUser(persist=True) as user:
project = await project_factory(user)
input_dataset = await dataset_factory(
project, name="input", type="zarr"
)
output_dataset = await dataset_factory(project, name="output")
workflow = await workflow_factory(project_id=project.id)
task = await task_factory()
await workflow.insert_task(task.id, db=db)

payload = dict(
project_id=project.id,
input_dataset_id=input_dataset.id,
output_dataset_id=output_dataset.id,
workflow_id=workflow.id,
overwrite_input=False,
)
debug(input_dataset)
debug(output_dataset)

res = await client.post(
f"{PREFIX}/apply/",
json=payload,
)

debug(res.json())
assert res.status_code == 422
assert "empty resource_list" in res.json()["detail"]

0 comments on commit c73ec18

Please sign in to comment.