Has anyone experienced they can’t delete a flow/de...
# ask-community
t
Has anyone experienced they can’t delete a flow/deployment? 🧵*→*
1
Im trying to delete a flow and a deployment. This one: https://github.com/anna-geller/dataflow-ops/blob/main/utilities/maintenance.py When I try to delete via the UI I get
Failed to delete deployments
and if I delete with API I get a TimeoutError. I’ve searched Slack and online, but haven’t found anything similar.
a
you likely have a large number of completed flow runs that are trying to get deleted as part of the delete request try deleting those flow runs first and then delete a deployment
you could do that by selecting all runs from that deployment/flow from the UI and click delete (perhaps try doing it step by step) - the issue here is that if you have a lot of them, Prefect will make a lot of API calls and they may timeout if you try deleting a very large number of runs at once -- we may add a bulk soft delete operation for that later but this is not implemented at the time of writing https://discourse.prefect.io/t/when-i-try-to-delete-a-prefect-deployment-i-get-an-error-failed-to-delete-deployment-how-to-solve-it/2083
t
Hi @Anna Geller and thanks for the input. Because
maintainance
was set to 10s and the que crashed somehow, there are 1000s (99244) of pending jobs for a que that does not exist anymore. I cant seem to find a way to bulk select and delete Flow Runs in the UI?
prefect flow-run delete
does not seems to allow any deletion based on tags or flow name?
a
this should work
but I agree doing it from the UI is clunky - can you try deleting the flow?
this should work - just pass the deployment ID and it will delete all runs one by one:
Copy code
import asyncio
from prefect import get_client
from prefect.orion.schemas.filters import DeploymentFilter


async def remove_runs_from_a_given_deployment_id(id_):
    client = get_client()
    runs = await client.read_flow_runs(
        deployment_filter=DeploymentFilter(id={"any_": [id_]})
    )
    for run in runs:
        print(f"Deleting run: {run.name}")
        await client.delete_flow_run(run.id)
        print(f"Run with UUID {run.id} deleted")


if __name__ == "__main__":
    deployment_id = "bd413bc3-ae3b-49eb-bddf-56a6c4663af2"
    asyncio.run(remove_runs_from_a_given_deployment_id(deployment_id))
t
Thanks! This works. However, it only deletes ~70 runs before stopping again. I can see that
client
only has a method for deleting one flow run at the time. Is there a rate limit on the API?
a
there are definitely rate limits on the API. If you pause that deployment and stop creating new flow runs, those will expire (will be removed) automatically based on your log retention period of your pricing tier: https://www.prefect.io/pricing/ on personal it's 7 days
might be worth just waiting for the problem to fix itself 😄 unless you're on self-hosted?
t
Ah great. Thats the easiest fix then. Nope not self-hosted and started a new deployment. Only annoyance with this number of flow runs is that the UI becomes unresponsive.
I will not run
for i in {1..500}; do python remove_flow_runs.py; done
then 😇
And thanks for the help!
a
sure! and welcome to the club of pragmatic (lazy?) programmers 🙌