Skip to content

prefect.server.models.flow_run_states

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

delete_flow_run_state async

Delete a flow run state by id.

Parameters:

Name Type Description Default
session sa.orm.Session

A database session

required
flow_run_state_id UUID

a flow run state id

required

Returns:

Name Type Description
bool bool

whether or not the flow run state was deleted

Source code in prefect/server/models/flow_run_states.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@inject_db
async def delete_flow_run_state(
    session: sa.orm.Session, flow_run_state_id: UUID, db: PrefectDBInterface
) -> 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 Type Description Default
session sa.orm.Session

A database session

required
flow_run_state_id UUID

a flow run state id

required

Returns:

Type Description

db.FlowRunState: the flow state

Source code in prefect/server/models/flow_run_states.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@inject_db
async def read_flow_run_state(
    session: sa.orm.Session, flow_run_state_id: UUID, db: PrefectDBInterface
):
    """
    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 Type Description Default
session sa.orm.Session

A database session

required
flow_run_id UUID

the flow run id

required

Returns:

Type Description

List[db.FlowRunState]: the flow run states

Source code in prefect/server/models/flow_run_states.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@inject_db
async def read_flow_run_states(
    session: sa.orm.Session, flow_run_id: UUID, db: PrefectDBInterface
):
    """
    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()