Skip to content

prefect.server.models.task_run_states

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

delete_task_run_state(session, task_run_state_id) async

Delete a task run state by id.

Parameters:

Name Type Description Default
session AsyncSession

A database session

required
task_run_state_id UUID

a task run state id

required

Returns:

Name Type Description
bool bool

whether or not the task run state was deleted

Source code in src/prefect/server/models/task_run_states.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
async def delete_task_run_state(session: AsyncSession, task_run_state_id: UUID) -> bool:
    """
    Delete a task run state by id.

    Args:
        session: A database session
        task_run_state_id: a task run state id

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

    result = await session.execute(
        delete(orm_models.TaskRunState).where(
            orm_models.TaskRunState.id == task_run_state_id
        )
    )
    return result.rowcount > 0

read_task_run_state(session, task_run_state_id) async

Reads a task run state by id.

Parameters:

Name Type Description Default
session AsyncSession

A database session

required
task_run_state_id UUID

a task run state id

required

Returns:

Type Description
Union[TaskRunState, None]

orm_models.TaskRunState: the task state

Source code in src/prefect/server/models/task_run_states.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
async def read_task_run_state(
    session: AsyncSession, task_run_state_id: UUID
) -> Union[orm_models.TaskRunState, None]:
    """
    Reads a task run state by id.

    Args:
        session: A database session
        task_run_state_id: a task run state id

    Returns:
        orm_models.TaskRunState: the task state
    """

    return await session.get(orm_models.TaskRunState, task_run_state_id)

read_task_run_states(session, task_run_id) async

Reads task runs states for a task run.

Parameters:

Name Type Description Default
session AsyncSession

A database session

required
task_run_id UUID

the task run id

required

Returns:

Type Description
Sequence[TaskRunState]

List[orm_models.TaskRunState]: the task run states

Source code in src/prefect/server/models/task_run_states.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
async def read_task_run_states(
    session: AsyncSession, task_run_id: UUID
) -> Sequence[orm_models.TaskRunState]:
    """
    Reads task runs states for a task run.

    Args:
        session: A database session
        task_run_id: the task run id

    Returns:
        List[orm_models.TaskRunState]: the task run states
    """

    query = (
        select(orm_models.TaskRunState)
        .filter_by(task_run_id=task_run_id)
        .order_by(orm_models.TaskRunState.timestamp)
    )
    result = await session.execute(query)
    return result.scalars().unique().all()