Skip to content

Commit a517c11

Browse files
committed
Rename function and favor verbose usage
This makes it more clear where the data is actually coming from.
1 parent 2b1849e commit a517c11

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/database/flows.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sqlalchemy import Connection, Row, text
44

55

6-
def get_flow_subflows(flow_id: int, expdb: Connection) -> Sequence[Row]:
6+
def get_subflows(for_flow: int, expdb: Connection) -> Sequence[Row]:
77
return cast(
88
Sequence[Row],
99
expdb.execute(
@@ -14,12 +14,12 @@ def get_flow_subflows(flow_id: int, expdb: Connection) -> Sequence[Row]:
1414
WHERE parent = :flow_id
1515
""",
1616
),
17-
parameters={"flow_id": flow_id},
17+
parameters={"flow_id": for_flow},
1818
),
1919
)
2020

2121

22-
def get_flow_tags(flow_id: int, expdb: Connection) -> list[str]:
22+
def get_tags(flow_id: int, expdb: Connection) -> list[str]:
2323
tag_rows = expdb.execute(
2424
text(
2525
"""
@@ -33,7 +33,7 @@ def get_flow_tags(flow_id: int, expdb: Connection) -> list[str]:
3333
return [tag.tag for tag in tag_rows]
3434

3535

36-
def get_flow_parameters(flow_id: int, expdb: Connection) -> Sequence[Row]:
36+
def get_parameters(flow_id: int, expdb: Connection) -> Sequence[Row]:
3737
return cast(
3838
Sequence[Row],
3939
expdb.execute(
@@ -49,7 +49,7 @@ def get_flow_parameters(flow_id: int, expdb: Connection) -> Sequence[Row]:
4949
)
5050

5151

52-
def get_flow_by_name(name: str, external_version: str, expdb: Connection) -> Row | None:
52+
def get_by_name(name: str, external_version: str, expdb: Connection) -> Row | None:
5353
"""Gets flow by name and external version."""
5454
return expdb.execute(
5555
text(
@@ -63,7 +63,7 @@ def get_flow_by_name(name: str, external_version: str, expdb: Connection) -> Row
6363
).one_or_none()
6464

6565

66-
def get_flow(flow_id: int, expdb: Connection) -> Row | None:
66+
def get_by_id(flow_id: int, expdb: Connection) -> Row | None:
6767
return expdb.execute(
6868
text(
6969
"""

src/routers/openml/flows.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import http.client
22
from typing import Annotated, Literal
33

4+
import database.flows
45
from core.conversions import _str_to_num
5-
from database.flows import get_flow as db_get_flow
6-
from database.flows import get_flow_by_name, get_flow_parameters, get_flow_subflows, get_flow_tags
76
from fastapi import APIRouter, Depends, HTTPException
87
from schemas.flows import Flow, Parameter
98
from sqlalchemy import Connection
@@ -20,7 +19,7 @@ def flow_exists(
2019
expdb: Annotated[Connection, Depends(expdb_connection)],
2120
) -> dict[Literal["flow_id"], int]:
2221
"""Check if a Flow with the name and version exists, if so, return the flow id."""
23-
flow = get_flow_by_name(name, version, expdb)
22+
flow = database.flows.get_by_name(name, version, expdb)
2423
if flow is None:
2524
raise HTTPException(
2625
status_code=http.client.NOT_FOUND,
@@ -31,11 +30,11 @@ def flow_exists(
3130

3231
@router.get("/{flow_id}")
3332
def get_flow(flow_id: int, expdb: Annotated[Connection, Depends(expdb_connection)] = None) -> Flow:
34-
flow = db_get_flow(flow_id, expdb)
33+
flow = database.flows.get_by_id(flow_id, expdb)
3534
if not flow:
3635
raise HTTPException(status_code=http.client.NOT_FOUND, detail="Flow not found")
3736

38-
parameter_rows = get_flow_parameters(flow_id, expdb)
37+
parameter_rows = database.flows.get_parameters(flow_id, expdb)
3938
parameters = [
4039
Parameter(
4140
name=parameter.name,
@@ -49,9 +48,8 @@ def get_flow(flow_id: int, expdb: Annotated[Connection, Depends(expdb_connection
4948
for parameter in parameter_rows
5049
]
5150

52-
tags = get_flow_tags(flow_id, expdb)
53-
54-
flow_rows = get_flow_subflows(flow_id, expdb)
51+
tags = database.flows.get_tags(flow_id, expdb)
52+
flow_rows = database.flows.get_subflows(for_flow=flow_id, expdb=expdb)
5553
subflows = [
5654
{
5755
"identifier": flow.identifier,

0 commit comments

Comments
 (0)