Skip to content

Asset-triggered DAGs miss events from concurrently completing dynamic mapped tasks #54659

Closed

Description

@marclamberti

Apache Airflow version

3.0.4

If "Other Airflow 2 version" selected, which one?

No response

What happened?

When using dynamic task mapping with asset outlets, if multiple mapped task instances are completed in quick succession (or at the same time) and produce events for the same asset, the downstream asset-triggered DAG does not receive all asset events in the triggering_asset_events context variable.

Context:

  • DAG A has a dynamically mapped task with outlets=[Asset("example")]
  • When the mapped task expands to 3 instances, each instance creates an AssetEvent upon
    completion
  • DAG B is triggered by Asset("example")
  • DAG B is triggered once (expected behavior due to batching events)
  • However, triggering_asset_events in DAG B only contains 1 event instead of all 3
  • The missing events appear in the NEXT trigger of DAG B with an Asset Event

I think this might occur because:

  1. Each mapped task instance creates an AssetEvent and an AssetDagRunQueue entry in separate
    transactions
  2. The AssetDagRunQueue table has a composite primary key (asset_id, target_dag_id) preventing
    duplicates
  3. The scheduler uses MAX(AssetDagRunQueue.created_at) as the cutoff timestamp for which events
    to include
  4. Due to transaction timing, not all AssetEvents may be committed before the scheduler
    processes the queue

What you think should happen instead?

When DAG B is triggered by multiple asset events from DAG A's mapped tasks, ALL events that caused the trigger should be available in the triggering_asset_events context variable
Or, DAG B should be triggered more than once to "consume" all Asset Events and not wait for another later Asset Event to process the previous ones.

How to reproduce

  1. Create DAG A with dynamic task mapping:
from airflow.sdk import Asset, task, dag
from datetime import datetime

asset = Asset("s3://bucket/asset_c")

@dag(
      start_date=datetime(2024, 1, 1),
      schedule="@daily",
      catchup=False,
def dag_a():

      @task(outlets=[asset])
      def produce_asset_event(item):
          print(f"Producing event for item {item}")
          return {"item": item}

      # This creates 3 mapped task instances
      produce_asset_event.expand(item=[1, 2, 3])

dag_a()
  1. Create DAG B triggered by the asset:
from datetime import datetime

@dag(
      schedule=[asset]
)
def dag_b():

      @task
      def consume_events(triggering_asset_events=None):
          print(f"Received events: {triggering_asset_events}")

          # Count events for asset_c
          asset_events = triggering_asset_events[asset]
          print(f"Number of events for asset_c: {len(asset_events)}")

      consume_events()
dag_b()

Operating System

MacOS 15.5

Versions of Apache Airflow Providers

No response

Deployment

Astronomer

Deployment details

Astro CLI

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. vikrantkumar-max commented on Aug 19, 2025

    @vikrantkumar-max
    Contributor

    Hi , I would like to work on this issue

  2. vikramkoka commented on Aug 27, 2025

    @vikramkoka
    Contributor
  3. added
    area:data-aware-schedulingassets, datasets, AIP-48, AIP-76, AIP-74, Asset Partitions
    and removed
    needs-triagelabel for new issues that we didn't triage yet
    on Aug 27, 2025
  4. added
    priority:highHigh priority bug that should be patched quickly but does not require immediate new release
    on Sep 2, 2025
  5. phanikumv commented on Sep 16, 2025

    @phanikumv
    Contributor

    Lets not add this for 3.1.0 , as we are very close to the deadline and the review comments need to be addressed.

  6. dipesh747 commented on Oct 22, 2025

    @dipesh747

    The same issue occurs when multiple upstream dags simultaneously trigger the same downstream dag, even if the Asset which is doing the triggering is different. If it happens in the same timestamp, only one trigger gets picked up.

    I would like functionality where one asset run can always trigger one dag regardless of any other concurrency on the schedule.

  7. jgoedeke commented on Oct 29, 2025

    @jgoedeke
  8. potiuk commented on Mar 2, 2026

    @potiuk
    Member

    @vikrantkumar-max We are unassigning you from this issue as part of our updated assignment policy.

    This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.

    We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.

  9. Vamsi-klu commented on Aug 23, 2026

    @Vamsi-klu
  10. added 3 commits that reference this issue on Aug 24, 2026
    dc9227b
    5bfae5c
    25da1f2
  11. uranusjr commented on Sep 1, 2026

    @uranusjr
    Member

    This was fixed as a side effect of #70972 changing ADRQ’s PK from (asset_id, target_dag_id) to (target_dag_id, asset_event_id). There’s a long chain of reasons behind the change, but for this issue specifically only the end result is important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions