Tom Han
09/02/2025, 8:54 PM@flow
def A():
...
ret = B()
would B be treated like a subflow?Marvin
09/02/2025, 8:54 PMMarvin
09/02/2025, 8:59 PMret = B()
inside A
) creates a subflow run.
What that means:
- Execution: Runs in-process with the parent flow, synchronously. A
will wait for B()
to finish and ret
is the return value of B
.
- UI/lineage: You’ll see a nested “subflow” under the parent flow run in the Prefect UI (the child run has the parent’s run ID).
- Errors: Unhandled exceptions in B
propagate to A
and can fail the parent run.
- Parameters: Pass arguments to B
like a normal Python function; Prefect records them for the subflow run.
If you want B
to run as an independent flow run (e.g., on different infrastructure or not nested in the UI), deploy B
and trigger it via run_deployment
. By default, run_deployment(..., as_subflow=True)
will still nest under the caller; set as_subflow=False
to decouple.
Example:
from prefect import flow
from prefect.deployments.flow_runs import run_deployment
@flow
def B(x: int = 1) -> int:
return x + 1
@flow
def A():
# Subflow (in-process, nested in UI)
r1 = B(2)
# Separate deployment run (still nested by default)
child = run_deployment(
name="B/my-deployment",
parameters={"x": 3},
as_subflow=True, # set to False to make it a top-level run
)
return r1
Docs:
- Running deployments (includes as_subflow
): Run deployments
- Creating deployments: Create deployments