Skip to content

Commit 42cc5e6

Browse files
authored
🐛 Fixes mismatch on error status-code for start-computation (#5994)
1 parent 9d7e144 commit 42cc5e6

File tree

5 files changed

+17
-24
lines changed

5 files changed

+17
-24
lines changed

api/specs/web-server/_computations.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,16 @@ async def get_computation(project_id: ProjectID):
2929
"/computations/{project_id}:start",
3030
response_model=Envelope[_ComputationStarted],
3131
responses={
32-
status.HTTP_404_NOT_FOUND: {
33-
"description": "Project/wallet/pricing details not found"
34-
},
3532
status.HTTP_402_PAYMENT_REQUIRED: {
36-
"description": "Insufficient osparc credits"
37-
},
38-
status.HTTP_406_NOT_ACCEPTABLE: {
39-
"description": "Cluster not found",
33+
"description": "Insufficient credits to run computation"
4034
},
41-
status.HTTP_503_SERVICE_UNAVAILABLE: {
42-
"description": "Service not available",
43-
},
44-
status.HTTP_422_UNPROCESSABLE_ENTITY: {
45-
"description": "Configuration error",
35+
status.HTTP_404_NOT_FOUND: {
36+
"description": "Project/wallet/pricing details were not found"
4637
},
47-
status.HTTP_402_PAYMENT_REQUIRED: {"description": "Payment required"},
38+
status.HTTP_406_NOT_ACCEPTABLE: {"description": "Cluster not found"},
4839
status.HTTP_409_CONFLICT: {"description": "Project already started"},
40+
status.HTTP_422_UNPROCESSABLE_ENTITY: {"description": "Configuration error"},
41+
status.HTTP_503_SERVICE_UNAVAILABLE: {"description": "Service not available"},
4942
},
5043
)
5144
async def start_computation(project_id: ProjectID, _start: ComputationStart):

services/director-v2/src/simcore_service_director_v2/api/routes/computations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@
9898
router = APIRouter()
9999

100100

101-
async def _check_pipeline_not_running(
101+
async def _check_pipeline_not_running_or_raise_409(
102102
comp_tasks_repo: CompTasksRepository, computation: ComputationCreate
103103
) -> None:
104104
pipeline_state = utils.get_pipeline_state_from_task_states(
105105
await comp_tasks_repo.list_computational_tasks(computation.project_id)
106106
)
107107
if utils.is_pipeline_running(pipeline_state):
108108
raise HTTPException(
109-
status_code=status.HTTP_403_FORBIDDEN,
109+
status_code=status.HTTP_409_CONFLICT,
110110
detail=f"Project {computation.project_id} already started, current state is {pipeline_state}",
111111
)
112112

@@ -324,7 +324,7 @@ async def create_computation( # noqa: PLR0913
324324
project: ProjectAtDB = await project_repo.get_project(computation.project_id)
325325

326326
# check if current state allow to modify the computation
327-
await _check_pipeline_not_running(comp_tasks_repo, computation)
327+
await _check_pipeline_not_running_or_raise_409(comp_tasks_repo, computation)
328328

329329
# create the complete DAG graph
330330
complete_dag = create_complete_dag(project.workbench)

services/director-v2/tests/integration/01/test_computation_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ async def test_update_and_delete_computation(
835835
), f"pipeline is not in the expected starting state but in {task_out.state}"
836836

837837
# now try to update the pipeline, is expected to be forbidden
838-
with pytest.raises(httpx.HTTPStatusError, match=f"{status.HTTP_403_FORBIDDEN}"):
838+
with pytest.raises(httpx.HTTPStatusError, match=f"{status.HTTP_409_CONFLICT}"):
839839
await create_pipeline(
840840
async_client,
841841
project=sleepers_project,

services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
472472
this.getStudy().setPipelineRunning(false);
473473
}, this);
474474
req.addListener("fail", async e => {
475-
if (e.getTarget().getStatus() == "403") {
475+
if (e.getTarget().getStatus() == "409") {
476476
this.getStudyLogger().error(null, "Pipeline is already running");
477477
} else if (e.getTarget().getStatus() == "422") {
478478
this.getStudyLogger().info(null, "The pipeline is up-to-date");

services/web/server/tests/integration/02/test_computation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class _ExpectedResponseTuple(NamedTuple):
8585
ok: int
8686
created: int
8787
no_content: int
88-
forbidden: int
88+
confict: int
8989

9090
# pylint: disable=no-member
9191
def __str__(self) -> str:
@@ -105,7 +105,7 @@ def standard_role_response():
105105
ok=status.HTTP_401_UNAUTHORIZED,
106106
created=status.HTTP_401_UNAUTHORIZED,
107107
no_content=status.HTTP_401_UNAUTHORIZED,
108-
forbidden=status.HTTP_401_UNAUTHORIZED,
108+
confict=status.HTTP_401_UNAUTHORIZED,
109109
),
110110
),
111111
pytest.param(
@@ -114,7 +114,7 @@ def standard_role_response():
114114
ok=status.HTTP_200_OK,
115115
created=status.HTTP_201_CREATED,
116116
no_content=status.HTTP_204_NO_CONTENT,
117-
forbidden=status.HTTP_403_FORBIDDEN,
117+
confict=status.HTTP_409_CONFLICT,
118118
),
119119
),
120120
pytest.param(
@@ -123,7 +123,7 @@ def standard_role_response():
123123
ok=status.HTTP_200_OK,
124124
created=status.HTTP_201_CREATED,
125125
no_content=status.HTTP_204_NO_CONTENT,
126-
forbidden=status.HTTP_403_FORBIDDEN,
126+
confict=status.HTTP_409_CONFLICT,
127127
),
128128
),
129129
pytest.param(
@@ -132,7 +132,7 @@ def standard_role_response():
132132
ok=status.HTTP_200_OK,
133133
created=status.HTTP_201_CREATED,
134134
no_content=status.HTTP_204_NO_CONTENT,
135-
forbidden=status.HTTP_403_FORBIDDEN,
135+
confict=status.HTTP_409_CONFLICT,
136136
),
137137
),
138138
],
@@ -390,7 +390,7 @@ async def test_start_stop_computation(
390390
if not error:
391391
# starting again should be disallowed, since it's already running
392392
resp = await client.post(f"{url_start}")
393-
assert resp.status == expected.forbidden
393+
assert resp.status == expected.confict
394394

395395
assert "pipeline_id" in data
396396
assert data["pipeline_id"] == project_id

0 commit comments

Comments
 (0)