Skip to content

prefect.orion.models.flow_run_states

Functions for interacting with flow run state ORM objects. Intended for internal use by the Orion API.

delete_flow_run_state async

Delete a flow run state by id.

Parameters:

Name Description Default
session

A database session

Session
required
flow_run_state_id

a flow run state id

UUID
required

Returns:

Type Description
bool

whether or not the flow run state was deleted

Source code in prefect/orion/models/flow_run_states.py
@inject_db
async def delete_flow_run_state(
    session: sa.orm.Session, flow_run_state_id: UUID, db: OrionDBInterface
) -> bool:
    """
    Delete a flow run state by id.

    Args:
        session: A database session
        flow_run_state_id: a flow run state id

    Returns:
        bool: whether or not the flow run state was deleted
    """

    result = await session.execute(
        delete(db.FlowRunState).where(db.FlowRunState.id == flow_run_state_id)
    )
    return result.rowcount > 0

read_flow_run_state async

Reads a flow run state by id.

Parameters:

Name Description Default
session

A database session

Session
required
flow_run_state_id

a flow run state id

UUID
required

Returns:

Type Description
db.FlowRunState

the flow state

Source code in prefect/orion/models/flow_run_states.py
@inject_db
async def read_flow_run_state(
    session: sa.orm.Session, flow_run_state_id: UUID, db: OrionDBInterface
):
    """
    Reads a flow run state by id.

    Args:
        session: A database session
        flow_run_state_id: a flow run state id

    Returns:
        db.FlowRunState: the flow state
    """

    return await session.get(db.FlowRunState, flow_run_state_id)

read_flow_run_states async

Reads flow runs states for a flow run.

Parameters:

Name Description Default
session

A database session

Session
required
flow_run_id

the flow run id

UUID
required

Returns:

Type Description
List[db.FlowRunState]

the flow run states

Source code in prefect/orion/models/flow_run_states.py
@inject_db
async def read_flow_run_states(
    session: sa.orm.Session, flow_run_id: UUID, db: OrionDBInterface
):
    """
    Reads flow runs states for a flow run.

    Args:
        session: A database session
        flow_run_id: the flow run id

    Returns:
        List[db.FlowRunState]: the flow run states
    """

    query = (
        select(db.FlowRunState)
        .filter_by(flow_run_id=flow_run_id)
        .order_by(db.FlowRunState.timestamp)
    )
    result = await session.execute(query)
    return result.scalars().unique().all()