Skip to content

Commit

Permalink
[API] Fix get pipelines return code in case of nonexistent project (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yanburman committed May 29, 2023
1 parent a1151c2 commit 83022b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mlrun/api/crud/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ def get_pipeline(
if project and project != "*":
run_project = self.resolve_project_from_pipeline(run)
if run_project != project:
raise mlrun.errors.MLRunInvalidArgumentError(
raise mlrun.errors.MLRunNotFoundError(
f"Pipeline run with id {run_id} is not of project {project}"
)
run = self._format_run(
db_session, run, format_, api_run_detail.to_dict()
)

except mlrun.errors.MLRunHTTPStatusError:
raise
except Exception as exc:
raise mlrun.errors.MLRunRuntimeError(
f"Failed getting kfp run: {err_to_str(exc)}"
Expand Down
16 changes: 16 additions & 0 deletions tests/api/api/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ def _generate_get_run_mock() -> kfp_server_api.models.api_run_detail.ApiRunDetai
)


def test_get_pipeline_nonexistent_project(
db: sqlalchemy.orm.Session,
client: fastapi.testclient.TestClient,
kfp_client_mock: kfp.Client,
) -> None:
format_ = (mlrun.common.schemas.PipelinesFormat.summary,)
project = "n0_pr0ject"
api_run_detail = _generate_get_run_mock()
_mock_get_run(kfp_client_mock, api_run_detail)
response = client.get(
f"projects/{project}/pipelines/{api_run_detail.run.id}",
params={"format": format_},
)
assert response.status_code == http.HTTPStatus.NOT_FOUND.value


def _generate_list_runs_mocks():
workflow_manifest = _generate_workflow_manifest()
return [
Expand Down

0 comments on commit 83022b5

Please sign in to comment.