Sophia Ponte
11/19/2025, 11:10 PMMarvin
11/19/2025, 11:10 PMMarvin
11/19/2025, 11:12 PMfrom prefect import flow
from prefect.runtime import flow_run
@flow
def child_flow():
parent_id = flow_run.parent_flow_run_id # None if this is a root flow
print(f"Parent flow run ID: {parent_id}")
return parent_id
Notes:
- flow_run.parent_flow_run_id returns the calling flow’s run ID when you’re in a subflow, otherwise None.
- Related helpers you may find useful: flow_run.id (current flow run), flow_run.root_flow_run_id (top-level flow in the chain).
If you need to fetch details about the parent run:
from prefect import flow
from prefect.runtime import flow_run
from prefect.client.orchestration import get_client
@flow
async def child_flow():
parent_id = flow_run.parent_flow_run_id
if parent_id:
async with get_client() as client:
parent = await client.read_flow_run(parent_id)
print(f"Parent flow name: {parent.name}")
return parent_id