https://prefect.io logo
Title
m

Mansour Zayer

01/23/2023, 5:21 PM
Hello. In Prefect 2, I'm using Orion API to read flow runs using
FlowRunFilter
. The problem is that
prefect.orion.schemas.filters.FlowRunFilter
requires a parameter of type
FlowRunFilterState
as
state
But
FlowRunFilterState
object doesn't exist in the API reference. There's only
FlowRunFilterStateType
How can I create such a filter?
FlowRunFilter(state=FlowRunFilterState(name='COMPLETED'))
(this doesn't work) Thank you
a

Alix Cook

01/23/2023, 6:15 PM
we do something like this:
flow_runs = await client.read_flow_runs(
    flow_run_filter=FlowRunFilter(
        state=FlowRunFilterState(type=FlowRunFilterStateType(any_=[StateType.RUNNING, StateType.PENDING])),
    ),
    sort=FlowRunSort.EXPECTED_START_TIME_DESC,
    limit=limit,
    offset=offset,
)
m

Mansour Zayer

01/23/2023, 6:51 PM
Thank you. Could you also show how you define the client object and what it is? I was using Client in prefect 1, but I thought it's not there anymore in prefect 2
a

Alix Cook

01/23/2023, 7:37 PM
from prefect.client import get_client
async with get_client() as client:
.... do stuff....
🙌 1