<@ULVA73B9P> I need to programmatically delete a l...
# ask-marvin
k
@Marvin I need to programmatically delete a lot of Pending flows. Ideally I would use the Python SDK or Rest API directly but the client method delete_flow_run is unable to delete flows in a Pending state.
raise UnfinishedRun(
prefect.exceptions.UnfinishedRun: Run is in PENDING state, its result is not available.)
Is this intended? Is there another way of cancelling or deleting Pending flowruns without using the UI
m
It seems that you can programmatically cancel a scheduled or in-progress flow run from the CLI, UI, REST API, or Python client, which moves the flow run into a "Cancelling" state. However, for cases where cancellation might fail, Prefect is working on improving the cancellation process. You may try the experimental enhanced cancellation by setting the
PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_CANCELLATION=True
on your worker or agents. If this doesn't work for you or you encounter any issues, Prefect suggests letting them know in Slack or opening a Github issue. Documentation mentioning cancellation: - Flow Concepts in Prefect Docs Currently, there doesn't seem to be a direct method to bulk delete or cancel multiple flow runs with a PENDING state, as suggested by a github issue that points out there is no easy way to clear, cancel, or delete many runs with arbitrary state or tag when needed. You may want to follow this issue for updates on whether such a feature will be implemented, or contribute to the discussion if you need a more immediate solution.