<@ULVA73B9P> how can I use trigger a flow using so...
# marvin-ai
p
@Marvin how can I use trigger a flow using something similar to run_deployment in a sync flow, where I want to trigger and move ahead in the original flow without waiting. I can't use await which is a constraint here
m
thought for 179.0 seconds
Great question. In Prefect 3.x,
run_deployment
is async, so in a synchronous flow you’ll want to trigger the deployment via the synchronous client and then keep going. Here’s the fire-and-forget pattern using
SyncPrefectClient
(no
await
):
Copy code
from prefect import flow
from prefect.client.orchestration import SyncPrefectClient

@flow
def parent_flow():
    with SyncPrefectClient() as client:
        # Look up the deployment by name (format: "flow_name/deployment_name")
        dep = client.read_deployment_by_name("my-flow/my-deployment")

        # Create a flow run from the deployment and immediately continue
        fr = client.create_flow_run_from_deployment(
            deployment_id=dep.id,
            parameters={"x": 1},           # optional
            flow_run_name="triggered-child",  # optional
            tags=["triggered-by-parent"],  # optional
            # work_queue_name="...",       # optional
            # scheduled_time=...,          # optional
            # idempotency_key="..."        # optional
        )

    print(f"Triggered child flow run: {fr.id}")
    # carry on with the rest of your parent flow logic...
Notes: - This submits the child run and returns immediately; it does not wait for the child run to start or finish. - If you already know the
deployment_id
, you can skip the
read_deployment_by_name
call and pass it directly. For reference, this uses the same server endpoint documented here: Create a flow run from a deployment. If you specifically want to use `run_deployment`: in 3.x it’s async and you’d still need to
await
it; even with
as_subflow=False
it’s not ideal for a purely sync context. The sync client above is the recommended approach. A couple of quick clarifications to tailor this: - Are you on Prefect 3.x? - Do you want the triggered run to appear as a “subflow” of the parent, or do you prefer it fully decoupled?