Hieu Tran

10/11/2022, 9:53 AM
I'm trying to get all the flow runs in Running state with client.read_flow_runs() but got error when initialize the FlowRunFilterState object. I couldn't find any example to do this from discourse, does anyone know what I did wrong?
Copy code
import asyncio
from prefect.client import get_client
from prefect.orion.schemas.states import StateType
from prefect.orion.schemas.filters import FlowRunFilter, FlowRunFilterState, FlowRunFilterStateType

async def main():
    client = get_client()
    state_type_filter = FlowRunFilterStateType(any_=[StateType.RUNNING])
    state_filter = FlowRunFilterState(state_type_filter)
    flow_filter = FlowRunFilter(state_filter)
    flow_runs = await client.read_flow_runs(flow_filter)

if __name__ == '__main__':

Traceback (most recent call last):
  File "", line 21, in <module>
  File "/usr/lib/python3.8/asyncio/", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/", line 616, in run_until_complete
    return future.result()
  File "", line 9, in main
    state_filter = FlowRunFilterState(state_type_filter)
  File "pydantic/", line 333, in pydantic.main.BaseModel.__init__
TypeError: __init__() takes exactly 1 positional argument (2 given)
I got it working by adding argument name when initialize objects
Copy code
state_filter = FlowRunFilterState(type=state_type_filter)
    flow_filter = FlowRunFilter(state=state_filter)
    flow_runs = await client.read_flow_runs(flow_run_filter=flow_filter)
🙏 1