I am running a flow from a flow with
run_deployment and an
idempotency_key. Sometimes, the child flow already exists and I want to do nothing. However in that case, a strange behavior happens:
When looking on the UI to my parent flow, the child flow has not been created but a task appears. This task stay pending forever, even if parent task succeed or fails.
I am wondering if this is a bug or not. Also I am wondering if this task is taking cpu somewhere.
Easy to replicate:
from prefect.deployments.deployments import Deployment from flows import child_flow, parent_flow d1 = Deployment.build_from_flow( name='my_parent_deployment', flow=parent_flow, ) d2 = Deployment.build_from_flow( name='my_child_deployment', flow=child_flow, ) d1.apply() d2.apply()
from prefect import flow, get_run_logger from prefect.deployments import run_deployment @flow async def parent_flow(): logger = get_run_logger() logger.info("Running parent flow") await run_deployment( name="child-flow/my_child_deployment", idempotency_key="my_idempotency_key", timeout=0, flow_run_name="child_flow_run", ) @flow async def child_flow(): logger = get_run_logger() logger.info("Running child flow")
And then run the parent deployment twice.
I think the task I see is the one below from
# Generate a task in the parent flow run to represent the result of the subflow dummy_task = Task( name=deployment_name, fn=lambda: None, version=deployment.version, )
This dummy task is only created when the child deployment is triggered inside a flow as we can see below from
flow_run_ctx = FlowRunContext.get() if flow_run_ctx: ....
If this behavior is a bug, then we should check that a flow run with the same idempotency_key does not exists before creating the