Hey <@ULVA73B9P>, I’m using the funtion `emit_even...
# ask-marvin
f
Hey @Marvin, I’m using the funtion
emit_event
, with a deployment trigger for another flow, but the flow got triggered 3 times, do you know what can be causing this ?
m
thought for 311.1 seconds
Short answer: one of three things usually does this. Likely culprits - You emitted the event three times - emit_event inside a loop or mapped task - the task/flow that calls emit_event retried (each attempt emits again) - Your trigger is set to “run for each match” - Broad conditions or multiple related resources on the event can yield multiple matches → multiple runs - You have overlapping triggers pointing to the same deployment - Easy to do if you created a few similar triggers while testing How to confirm in the UI (Prefect 3.x) - Events: filter by your event type. Do you see one event or three? Copy the event_ids. - Deployment trigger: open it → Runs/History. It’ll show which event_id fired it and how many matches it found. One event_id + three runs = trigger config; three different event_ids = emitter ran three times. - Each flow run page also shows “Triggered by” with the trigger and event_id. Common fixes - If retries are the cause, only emit on first attempt:
Copy code
from prefect import get_run_context
  from prefect.events import emit_event

  def emit_once(...):
      ctx = get_run_context()
      # Only on first attempt
      if not getattr(ctx, "task_run", None) or ctx.task_run.attempt == 1:
          emit_event(event="my.custom.event", resource={"prefect.resource.id": "something"})
- If mapping/loops are the cause, move emit_event outside the mapped task or guard with a flag so it runs once. - If the trigger is fanning out: - Disable “run for each match” (if enabled), or - Tighten conditions on resource/related filters so only one thing matches your event. - If you have overlapping triggers, consolidate them or add mutually exclusive conditions. - As a safety net, set a deployment concurrency limit with a “cancel oldest” policy to avoid multiple active runs. If you can share: - Your trigger definition (screenshot/text of the conditions, and whether “run for each” is on) - Where emit_event is called (inside a loop/map? any retries?) - A couple of event_ids from the Event feed …I can point to the exact root cause instead of playing guess-the-trigger. Docs, in case you enjoy light bedtime reading: - Event triggers: Event triggers concepts - Creating deployment triggers: How to create deployment triggers