Skip to content

Commit

Permalink
[Pipelines] Fix project resolution on get pipeline endpoint (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedingber committed Aug 25, 2021
1 parent 02bbe95 commit 8bbc759
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
11 changes: 2 additions & 9 deletions mlrun/api/crud/pipelines.py
Expand Up @@ -89,15 +89,8 @@ def get_pipeline(
if api_run_detail.run:
run = api_run_detail.to_dict()["run"]
if project and project != "*":
# we need to resolve the project from the returned run for the project enforcement here, so we
# can't really get back only the names here
computed_format = (
mlrun.api.schemas.PipelinesFormat.metadata_only
if format_ == mlrun.api.schemas.PipelinesFormat.name_only
else format_
)
run_for_project = self._format_run(db_session, run, computed_format)
if run_for_project["project"] != project:
run_project = self.resolve_project_from_pipeline(run)
if run_project != project:
raise mlrun.errors.MLRunInvalidArgumentError(
f"Pipeline run with id {run_id} is not of project {project}"
)
Expand Down
30 changes: 30 additions & 0 deletions tests/api/api/test_pipelines.py
Expand Up @@ -96,6 +96,36 @@ def test_get_pipeline_formats(
_assert_get_pipeline_response(expected_run, response)


def test_get_pipeline_specific_project(
db: sqlalchemy.orm.Session,
client: fastapi.testclient.TestClient,
kfp_client_mock: kfp.Client,
) -> None:
for format_ in [
mlrun.api.schemas.PipelinesFormat.full,
mlrun.api.schemas.PipelinesFormat.metadata_only,
mlrun.api.schemas.PipelinesFormat.summary,
mlrun.api.schemas.PipelinesFormat.name_only,
]:
project = "project-name"
api_run_detail = _generate_get_run_mock()
_mock_get_run(kfp_client_mock, api_run_detail)
mlrun.api.crud.Pipelines().resolve_project_from_pipeline = unittest.mock.Mock(
return_value=project
)
response = client.get(
f"/api/projects/{project}/pipelines/{api_run_detail.run.id}",
params={"format": format_},
)
expected_run = mlrun.api.crud.Pipelines()._format_run(
db, api_run_detail.to_dict()["run"], format_, api_run_detail.to_dict()
)
_assert_get_pipeline_response(expected_run, response)

# revert mock setting (it's global function, without reloading it the mock will persist to following tests)
importlib.reload(mlrun.api.crud)


def test_list_pipelines_specific_project(
db: sqlalchemy.orm.Session,
client: fastapi.testclient.TestClient,
Expand Down

0 comments on commit 8bbc759

Please sign in to comment.