Hi trying to build something on top of prefect to ...
# ask-community
e
Hi trying to build something on top of prefect to handle zombie flow I'm getting the following error from a container outside the prefect server but using the
prefecthq/prefect:3.2.12.dev1-python3.12-conda
image
Copy code
future: <Task finished name='Task-3' coro=<background_handle_flows() done, defined at /app/main.py:48> exception=PydanticUserError('`StateCreate` is not fully defined; you should define all referenced types, then call `StateCreate.model_rebuild()`.')>
Traceback (most recent call last):
  File "/app/main.py", line 50, in background_handle_flows
    await handle_flows()
  File "/app/automate/prefect.py", line 49, in handle_flows
    await prefect_client.set_flow_run_state(flow_run.id, state, force=True)
  File "/opt/conda/envs/prefect/lib/python3.12/site-packages/prefect/client/orchestration/_flow_runs/client.py", line 765, in set_flow_run_state
    state_create = to_state_create(state)
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/prefect/lib/python3.12/site-packages/prefect/states.py", line 67, in to_state_create
    return StateCreate(
           ^^^^^^^^^^^^
  File "/opt/conda/envs/prefect/lib/python3.12/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/prefect/lib/python3.12/site-packages/pydantic/_internal/_mock_val_ser.py", line 100, in __getattr__
    raise PydanticUserError(self._error_message, code=self._code)
pydantic.errors.PydanticUserError: `StateCreate` is not fully defined; you should define all referenced types, then call `StateCreate.model_rebuild()`.
Woudl you have any hint ? I'm using the following code
Copy code
prefect_client = get_client()
            flow_runs = await prefect_client.read_flow_runs(
                flow_run_filter=schemas.filters.FlowRunFilter(
                    deployment_id=schemas.filters.FlowRunFilterDeploymentId(any_=[deployment_id]),
                    state=schemas.filters.FlowRunFilterState(
                        type=schemas.filters.FlowRunFilterStateType(any_=[StateType.RUNNING])
                    )
                )
            )
            for flow_run in flow_runs:
                state = flow_run.state.copy(
                    update= {
                        "name": "Cancelled", 
                        "type": StateType.CANCELLED
                    }
                )
                await prefect_client.set_flow_run_state(flow_run.id, state, force=True)