From 1a5dea66eb1dd77b8c81ac8763e3e3032954b483 Mon Sep 17 00:00:00 2001 From: Jayant Kernel Date: Sat, 7 Mar 2026 22:57:47 +0530 Subject: [PATCH 1/4] fix(flows): replace GET /flows/exists with POST to support URI-unsafe flow names The GET /flows/exists/{name}/{external_version} endpoint broke for flows with URI-unsafe characters in their names (e.g. sklearn flows with parentheses). Replaced with POST /flows/exists accepting name and external_version in the request body, resolving issue #166. Closes #166 --- src/routers/openml/flows.py | 13 +++++++++---- tests/routers/openml/flows_test.py | 12 ++++++------ .../openml/migration/flows_migration_test.py | 13 +++++++------ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/routers/openml/flows.py b/src/routers/openml/flows.py index cb6df5d9..2c941aa5 100644 --- a/src/routers/openml/flows.py +++ b/src/routers/openml/flows.py @@ -2,6 +2,7 @@ from typing import Annotated, Literal from fastapi import APIRouter, Depends, HTTPException +from pydantic import BaseModel from sqlalchemy import Connection import database.flows @@ -12,14 +13,18 @@ router = APIRouter(prefix="/flows", tags=["flows"]) -@router.get("/exists/{name}/{external_version}") +class FlowExistsBody(BaseModel): + name: str + external_version: str + + +@router.post("/exists") def flow_exists( - name: str, - external_version: str, + body: FlowExistsBody, expdb: Annotated[Connection, Depends(expdb_connection)], ) -> dict[Literal["flow_id"], int]: """Check if a Flow with the name and version exists, if so, return the flow id.""" - flow = database.flows.get_by_name(name=name, external_version=external_version, expdb=expdb) + flow = database.flows.get_by_name(name=body.name, external_version=body.external_version, expdb=expdb) if flow is None: raise HTTPException( status_code=HTTPStatus.NOT_FOUND, diff --git a/tests/routers/openml/flows_test.py b/tests/routers/openml/flows_test.py index d5188d0e..65ce18dd 100644 --- a/tests/routers/openml/flows_test.py +++ b/tests/routers/openml/flows_test.py @@ -7,7 +7,7 @@ from sqlalchemy import Connection from starlette.testclient import TestClient -from routers.openml.flows import flow_exists +from routers.openml.flows import FlowExistsBody, flow_exists from tests.conftest import Flow @@ -25,7 +25,7 @@ def test_flow_exists_calls_db_correctly( mocker: MockerFixture, ) -> None: mocked_db = mocker.patch("database.flows.get_by_name") - flow_exists(name, external_version, expdb_test) + flow_exists(FlowExistsBody(name=name, external_version=external_version), expdb_test) mocked_db.assert_called_once_with( name=name, external_version=external_version, @@ -47,26 +47,26 @@ def test_flow_exists_processes_found( "database.flows.get_by_name", return_value=fake_flow, ) - response = flow_exists("name", "external_version", expdb_test) + response = flow_exists(FlowExistsBody(name="name", external_version="external_version"), expdb_test) assert response == {"flow_id": fake_flow.id} def test_flow_exists_handles_flow_not_found(mocker: MockerFixture, expdb_test: Connection) -> None: mocker.patch("database.flows.get_by_name", return_value=None) with pytest.raises(HTTPException) as error: - flow_exists("foo", "bar", expdb_test) + flow_exists(FlowExistsBody(name="foo", external_version="bar"), expdb_test) assert error.value.status_code == HTTPStatus.NOT_FOUND assert error.value.detail == "Flow not found." def test_flow_exists(flow: Flow, py_api: TestClient) -> None: - response = py_api.get(f"/flows/exists/{flow.name}/{flow.external_version}") + response = py_api.post("/flows/exists", json={"name": flow.name, "external_version": flow.external_version}) assert response.status_code == HTTPStatus.OK assert response.json() == {"flow_id": flow.id} def test_flow_exists_not_exists(py_api: TestClient) -> None: - response = py_api.get("/flows/exists/foo/bar") + response = py_api.post("/flows/exists", json={"name": "foo", "external_version": "bar"}) assert response.status_code == HTTPStatus.NOT_FOUND assert response.json()["detail"] == "Flow not found." diff --git a/tests/routers/openml/migration/flows_migration_test.py b/tests/routers/openml/migration/flows_migration_test.py index 674bc439..128e0598 100644 --- a/tests/routers/openml/migration/flows_migration_test.py +++ b/tests/routers/openml/migration/flows_migration_test.py @@ -18,9 +18,8 @@ def test_flow_exists_not( py_api: TestClient, php_api: TestClient, ) -> None: - path = "exists/foo/bar" - py_response = py_api.get(f"/flows/{path}") - php_response = php_api.get(f"/flow/{path}") + py_response = py_api.post("/flows/exists", json={"name": "foo", "external_version": "bar"}) + php_response = php_api.get("/flow/exists/foo/bar") assert py_response.status_code == HTTPStatus.NOT_FOUND assert php_response.status_code == HTTPStatus.OK @@ -36,9 +35,11 @@ def test_flow_exists( py_api: TestClient, php_api: TestClient, ) -> None: - path = f"exists/{persisted_flow.name}/{persisted_flow.external_version}" - py_response = py_api.get(f"/flows/{path}") - php_response = php_api.get(f"/flow/{path}") + py_response = py_api.post( + "/flows/exists", + json={"name": persisted_flow.name, "external_version": persisted_flow.external_version}, + ) + php_response = php_api.get(f"/flow/exists/{persisted_flow.name}/{persisted_flow.external_version}") assert py_response.status_code == php_response.status_code, php_response.content From 2f60ac46855ca5d1260a176c75f32328497a5d08 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Mar 2026 18:20:16 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/routers/openml/flows.py | 4 +++- tests/routers/openml/flows_test.py | 8 ++++++-- tests/routers/openml/migration/flows_migration_test.py | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/routers/openml/flows.py b/src/routers/openml/flows.py index 2c941aa5..16913f86 100644 --- a/src/routers/openml/flows.py +++ b/src/routers/openml/flows.py @@ -24,7 +24,9 @@ def flow_exists( expdb: Annotated[Connection, Depends(expdb_connection)], ) -> dict[Literal["flow_id"], int]: """Check if a Flow with the name and version exists, if so, return the flow id.""" - flow = database.flows.get_by_name(name=body.name, external_version=body.external_version, expdb=expdb) + flow = database.flows.get_by_name( + name=body.name, external_version=body.external_version, expdb=expdb + ) if flow is None: raise HTTPException( status_code=HTTPStatus.NOT_FOUND, diff --git a/tests/routers/openml/flows_test.py b/tests/routers/openml/flows_test.py index 65ce18dd..f6a65351 100644 --- a/tests/routers/openml/flows_test.py +++ b/tests/routers/openml/flows_test.py @@ -47,7 +47,9 @@ def test_flow_exists_processes_found( "database.flows.get_by_name", return_value=fake_flow, ) - response = flow_exists(FlowExistsBody(name="name", external_version="external_version"), expdb_test) + response = flow_exists( + FlowExistsBody(name="name", external_version="external_version"), expdb_test + ) assert response == {"flow_id": fake_flow.id} @@ -60,7 +62,9 @@ def test_flow_exists_handles_flow_not_found(mocker: MockerFixture, expdb_test: C def test_flow_exists(flow: Flow, py_api: TestClient) -> None: - response = py_api.post("/flows/exists", json={"name": flow.name, "external_version": flow.external_version}) + response = py_api.post( + "/flows/exists", json={"name": flow.name, "external_version": flow.external_version} + ) assert response.status_code == HTTPStatus.OK assert response.json() == {"flow_id": flow.id} diff --git a/tests/routers/openml/migration/flows_migration_test.py b/tests/routers/openml/migration/flows_migration_test.py index 128e0598..5ee8e592 100644 --- a/tests/routers/openml/migration/flows_migration_test.py +++ b/tests/routers/openml/migration/flows_migration_test.py @@ -39,7 +39,9 @@ def test_flow_exists( "/flows/exists", json={"name": persisted_flow.name, "external_version": persisted_flow.external_version}, ) - php_response = php_api.get(f"/flow/exists/{persisted_flow.name}/{persisted_flow.external_version}") + php_response = php_api.get( + f"/flow/exists/{persisted_flow.name}/{persisted_flow.external_version}" + ) assert py_response.status_code == php_response.status_code, php_response.content From 3ff845fbfdc3ce56721c908503eb6eff6f17b137 Mon Sep 17 00:00:00 2001 From: Jayant Kernel Date: Sat, 7 Mar 2026 23:57:42 +0530 Subject: [PATCH 3/4] style: fix trailing comma in flow_exists db call --- src/routers/openml/flows.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/routers/openml/flows.py b/src/routers/openml/flows.py index 16913f86..b06f5369 100644 --- a/src/routers/openml/flows.py +++ b/src/routers/openml/flows.py @@ -25,7 +25,9 @@ def flow_exists( ) -> dict[Literal["flow_id"], int]: """Check if a Flow with the name and version exists, if so, return the flow id.""" flow = database.flows.get_by_name( - name=body.name, external_version=body.external_version, expdb=expdb + name=body.name, + external_version=body.external_version, + expdb=expdb, ) if flow is None: raise HTTPException( From a771b69a8f6d7ff6be4fd426bf01e7305b3c29e5 Mon Sep 17 00:00:00 2001 From: Jayant Kernel Date: Sun, 8 Mar 2026 00:06:40 +0530 Subject: [PATCH 4/4] refactor(flows): move FlowExistsBody to schemas and keep GET as deprecated wrapper - Move FlowExistsBody to schemas/flows.py for reusability - Keep GET /flows/exists/{name}/{version} as a deprecated thin wrapper around POST /flows/exists for backward compatibility - Update test imports accordingly --- src/routers/openml/flows.py | 18 +++++++++++------- src/schemas/flows.py | 5 +++++ tests/routers/openml/flows_test.py | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/routers/openml/flows.py b/src/routers/openml/flows.py index b06f5369..31562a08 100644 --- a/src/routers/openml/flows.py +++ b/src/routers/openml/flows.py @@ -2,22 +2,16 @@ from typing import Annotated, Literal from fastapi import APIRouter, Depends, HTTPException -from pydantic import BaseModel from sqlalchemy import Connection import database.flows from core.conversions import _str_to_num from routers.dependencies import expdb_connection -from schemas.flows import Flow, Parameter, Subflow +from schemas.flows import Flow, FlowExistsBody, Parameter, Subflow router = APIRouter(prefix="/flows", tags=["flows"]) -class FlowExistsBody(BaseModel): - name: str - external_version: str - - @router.post("/exists") def flow_exists( body: FlowExistsBody, @@ -37,6 +31,16 @@ def flow_exists( return {"flow_id": flow.id} +@router.get("/exists/{name}/{external_version}", deprecated=True) +def flow_exists_get( + name: str, + external_version: str, + expdb: Annotated[Connection, Depends(expdb_connection)], +) -> dict[Literal["flow_id"], int]: + """Deprecated: use POST /flows/exists instead.""" + return flow_exists(FlowExistsBody(name=name, external_version=external_version), expdb) + + @router.get("/{flow_id}") def get_flow(flow_id: int, expdb: Annotated[Connection, Depends(expdb_connection)] = None) -> Flow: flow = database.flows.get(flow_id, expdb) diff --git a/src/schemas/flows.py b/src/schemas/flows.py index a6cd479c..50e2491c 100644 --- a/src/schemas/flows.py +++ b/src/schemas/flows.py @@ -6,6 +6,11 @@ from pydantic import BaseModel, ConfigDict, Field +class FlowExistsBody(BaseModel): + name: str + external_version: str + + class Parameter(BaseModel): name: str default_value: Any diff --git a/tests/routers/openml/flows_test.py b/tests/routers/openml/flows_test.py index f6a65351..658d6325 100644 --- a/tests/routers/openml/flows_test.py +++ b/tests/routers/openml/flows_test.py @@ -7,7 +7,8 @@ from sqlalchemy import Connection from starlette.testclient import TestClient -from routers.openml.flows import FlowExistsBody, flow_exists +from routers.openml.flows import flow_exists +from schemas.flows import FlowExistsBody from tests.conftest import Flow