Alastair
10/23/2025, 12:47 PMshared_job_variables = {
# stuff here
}
deploy11 = my_flow.to_deployment(
name="deploy1",
cron="* 10 * * *",
job_variables=shared_job_variables,
work_queue_name="slow-queue",
tags=["awesome-things"],
triggers=[
DeploymentEventTrigger(
name="Trigger deploy1 after deploy2 completion",
expect={"prefect.flow-run.Completed"},
match_related={
"prefect.resource.name": "deploy2"
},
)
],
)
deploy2 = my_other_flow.to_deployment(
# similar setup
)
deployables = (deploy1, deploy2)
deploy(
*deployables,
work_pool_name=CONSTANTS.DEFAULT_WORKPOOL,
build=False,
push=False,
image=f"{docker_image}:{docker_tag}",
)Marvin
10/23/2025, 12:47 PMMarvin
10/23/2025, 1:12 PMtriggers=[DeploymentEventTrigger(...)] on a deployment)
2) Standalone Automations (created/managed directly via the Automations API)
If your “automations stop working when I deploy new versions,” it’s usually because deployment-linked triggers are re-created on each deploy. If the new deploy omits the triggers or the trigger’s match no longer matches (e.g., resource labels changed, flow/deployment name changed), they’ll stop firing.
Below are working patterns for both approaches and how to update them idempotently.
Option A — Keep using deployment-linked triggers (recreated on each deploy)
- Make sure you pass triggers=[...] on every deploy; they are regenerated and owned by that deployment.
- Use a stable matcher for the other deployment. Prefer matching by the other deployment’s id, or use the full resource name (“flow-name/deployment-name”), not just the deployment name.
Example (id-based match):
from prefect import flow
from prefect.deploy import deploy
from prefect.deployment import get_deployment
from prefect.events import DeploymentEventTrigger
@flow
def my_flow(): ...
@flow
def my_other_flow(): ...
# Resolve the source deployment id you want to listen to
src = get_deployment(name="my-other-flow/deploy2") # full "flow-name/deployment-name"
deploy1 = my_flow.to_deployment(
name="deploy1",
cron="* 10 * * *",
work_queue_name="slow-queue",
tags=["awesome-things"],
job_variables=shared_job_variables,
triggers=[
DeploymentEventTrigger(
expect={"prefect.flow-run.Completed"},
match_related={"prefect.resource.id": str(src.id)}, # stable match!
posture="Reactive",
)
],
)
deploy2 = my_other_flow.to_deployment(
name="deploy2",
cron="0 12 * * *",
work_queue_name="slow-queue",
tags=["awesome-things"],
job_variables=shared_job_variables,
)
deploy(
deploy1,
deploy2,
work_pool_name=CONSTANTS.DEFAULT_WORKPOOL,
build=False,
push=False,
image=f"{docker_image}:{docker_tag}",
)
Tips:
- If you prefer name matching, use the full resource name: match_related={"prefect.resource.name": "my-other-flow/deploy2"}. The “resource name” for a deployment is typically “flow-name/deployment-name”.
- These triggers are recreated at deploy time; if they “disappear,” it’s because your redeploy did not include them or the matcher no longer matches the new resource labels.
Docs:
- Creating deployment triggers
- Event trigger grammar and matching
Option B — Create a standalone Automation (persists across redeploys) and upsert it
If you want an automation that survives redeploys (and you update it programmatically), create it with the Automations API and “upsert” by name.
Example: when deployment B completes, run deployment A
```
from prefect.deployment import get_deployment
from prefect.events import Automation, EventTrigger
from prefect.events.actions import RunDeployment
def upsert_chain_automation(
name: str,
source_full_name: str, # e.g. "my-other-flow/deploy2"
target_full_name: str, # e.g. "my-flow/deploy1"
):
# Resolve deployment ids to make matching robust
src = get_deployment(name=source_full_name)
tgt = get_deployment(name=target_full_name)
trigger = EventTrigger(
expect={"prefect.flow-run.Completed"},
match_related={"prefect.resource.id": str(src.id)}, # or use prefect.resource.name with the full name
posture="Reactive",
)
# Action: run the target deployment (you can also pass parameters, tags, flow_run_name, etc.)
action = RunDeployment(deployment_id=str(tgt.id))
try:Marvin
10/23/2025, 1:12 PMtriggers=[...], they won’t be recreated.
- Matching by an imprecise label (e.g., using just “deploy2” instead of the full “flow-name/deploy2”, or using name when it changed) will stop the automation from firing.
- Matching by id is the most robust, since ids are stable for that specific deployment record.
Questions to confirm so I can tailor the fix:
- Are you trying to keep the triggers attached to the deployments, or would you prefer standalone Automations that survive redeploys?
- Can you share the exact “flow-name/deployment-name” for both deployments (or confirm if the names change between deploys)?
- Which Prefect version are you on (assuming 3.x)? This helps ensure we use the right API surface.