Skip to content

Commit

Permalink
Convert flow_run_input model utilities to use orm_models (#14409)
Browse files Browse the repository at this point in the history
  • Loading branch information
bunchesofdonald authored Jul 2, 2024
1 parent b899005 commit fd647f3
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/prefect/server/models/flow_run_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,37 @@
from sqlalchemy.ext.asyncio import AsyncSession

import prefect.server.schemas as schemas
from prefect.server.database.dependencies import inject_db
from prefect.server.database.interface import PrefectDBInterface
from prefect.server.database import orm_models


@inject_db
async def create_flow_run_input(
session: AsyncSession,
db: PrefectDBInterface,
flow_run_input: schemas.core.FlowRunInput,
) -> schemas.core.FlowRunInput:
model = db.FlowRunInput(**flow_run_input.model_dump())
model = orm_models.FlowRunInput(**flow_run_input.model_dump())
session.add(model)
await session.flush()

return schemas.core.FlowRunInput.model_validate(model, from_attributes=True)


@inject_db
async def filter_flow_run_input(
session: AsyncSession,
db: PrefectDBInterface,
flow_run_id: uuid.UUID,
prefix: str,
limit: int,
exclude_keys: List[str],
) -> List[schemas.core.FlowRunInput]:
query = (
sa.select(db.FlowRunInput)
sa.select(orm_models.FlowRunInput)
.where(
sa.and_(
db.FlowRunInput.flow_run_id == flow_run_id,
db.FlowRunInput.key.like(prefix + "%"),
db.FlowRunInput.key.not_in(exclude_keys),
orm_models.FlowRunInput.flow_run_id == flow_run_id,
orm_models.FlowRunInput.key.like(prefix + "%"),
orm_models.FlowRunInput.key.not_in(exclude_keys),
)
)
.order_by(db.FlowRunInput.created)
.order_by(orm_models.FlowRunInput.created)
.limit(limit)
)

Expand All @@ -51,17 +46,15 @@ async def filter_flow_run_input(
]


@inject_db
async def read_flow_run_input(
session: AsyncSession,
db: PrefectDBInterface,
flow_run_id: uuid.UUID,
key: str,
) -> Optional[schemas.core.FlowRunInput]:
query = sa.select(db.FlowRunInput).where(
query = sa.select(orm_models.FlowRunInput).where(
sa.and_(
db.FlowRunInput.flow_run_id == flow_run_id,
db.FlowRunInput.key == key,
orm_models.FlowRunInput.flow_run_id == flow_run_id,
orm_models.FlowRunInput.key == key,
)
)

Expand All @@ -73,17 +66,16 @@ async def read_flow_run_input(
return None


@inject_db
async def delete_flow_run_input(
session: AsyncSession,
db: PrefectDBInterface,
flow_run_id: uuid.UUID,
key: str,
) -> bool:
result = await session.execute(
sa.delete(db.FlowRunInput).where(
sa.delete(orm_models.FlowRunInput).where(
sa.and_(
db.FlowRunInput.flow_run_id == flow_run_id, db.FlowRunInput.key == key
orm_models.FlowRunInput.flow_run_id == flow_run_id,
orm_models.FlowRunInput.key == key,
)
)
)
Expand Down

0 comments on commit fd647f3

Please sign in to comment.