Repository navigation
Description
Apache Airflow version
2.10.5
If "Other Airflow 2 version" selected, which one?
No response
What happened?
Hey, it seems that Dataset events are not always triggering downstream DAG, even when there is free capacity in the cluster. I'm writing here, as I'm not sure if this is a bug or an expected behavior of Airflow.
I have a small demo to showcase what I mean. The demo consists of two DAGs, producer & consumer, one creating events on a dataset, and the other one running whenever new dataset events happen. A single run of the producer creates 4 new events, each one should be processed by the consumer DAG. But instead only some not all of those events are processed. On the first run 2 out of 4 events were processed. After the second run of the producer, the consumer was triggered with 3 events, two from the previous producer run, and one from the new batch. Three events are left not being processed at all.
Also it seems that sometimes the event source is missing from in the Airflow Dataset events view.
I don't see anything about those remaining events in the Scheduler's logs.
I noticed this problem originally in Amazon's MWAA service, and then I wanted to check if I can reproduce it in docker Airflow, and indeed I was able to reproduce it in Airflow running in Docker Compose.
What you think should happen instead?
I would expect all dataset events to trigger the downstream DAG.
How to reproduce
- Run Airflow in Docker Compose: https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html
- Create producer.py DAG:
from datetime import datetime
from airflow import DAG
from airflow.decorators import task
from airflow.datasets import Dataset
START_DATASET = Dataset("DA://start")
with DAG(
dag_id="producer",
schedule=None,
start_date=datetime(2024, 12, 3),
catchup=False,
) as dag:
@task
def generate_data():
return ["football ⚽", "jogging 🏃", "biking 🚴", "hiking 🥾"]
@task(outlets=[START_DATASET])
def trigger_down_streams(element: str, **context):
context["outlet_events"][START_DATASET].extra = {"Activity": element}
generated_data = generate_data()
trigger_down_streams.expand(element=generated_data)- Create consumer.py DAG:
from datetime import datetime
from airflow import DAG
from airflow.decorators import task
from airflow.datasets import Dataset
START_DATASET = Dataset("DA://start")
with DAG(
dag_id="consumer",
schedule=[START_DATASET],
start_date=datetime(2024, 12, 3),
catchup=False,
) as dag:
@task
def print_triggering_dataset_events(**context):
triggering_dataset_events = context.get("triggering_dataset_events")
print(triggering_dataset_events)
print_triggering_dataset_events()Operating System
MacOS - using docker compose
Versions of Apache Airflow Providers
No response
Deployment
Docker-Compose
Deployment details
No response
Anything else?
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Mar 5, 2025
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
amolsr commentedon Mar 6, 2025
Assign this issue to me.
amolsr commentedon Mar 6, 2025
Can you share the logs of execution for the parent dag?
dominikdAtStampli commentedon Mar 6, 2025
Hey, I recreated Airflow docker compose environment from scratch with the two DAGs I showed above, and ran the producer DAG once. Below I attach screenshots from the UI with the status of the events & dag runs as well as logs.
logs.zip
amolsr commentedon Mar 6, 2025
Hi, what is your requirement here? Are you trying to schedule four different runs on the same dataset? I don’t see a real production use case for this.
If you're using Mapped Tasks, the dataset has already been segmented, meaning it is no longer a single dataset. You can perform a fork and join operation if you need to trigger a downstream DAG and create a mapped task based on specific business logic. This logic may be the same as the upstream DAG or could differ.
Currently, Mapped Tasks are not mature enough to efficiently handle fork-and-join scenarios with datasets in between.
dominikdAtStampli commentedon Mar 7, 2025
Hey, I'm trying to create an event driven architecture in Airflow. Maybe I misunderstood the documentation and this video, but I thought that Airflow is able to trigger DAGs based on incoming dataset events. That it can decide if it wants to batch them into a single DAG execution, or run multiple DAG executions each with a subset of events.
That way I could send events to a Dataset either from other DAGs or from external systems using Airflow API, and have Airflow process all those events utilizing available capacity.
But I was surprised to see that pending dataset events don't always trigger downstream DAG, they just hang there and are picked up only after more events are sent. I'm not sure I understand what is the value of such an approach? Is this by design? Or is it an unexpected bug?
amolsr commentedon Mar 10, 2025
I believe this is intentional for airflow 2.5.2. However, Airflow 3.0 takes a more event-driven approach to scheduling. https://blog.det.life/airflow-3-0-promises-us-real-event-driven-scheduling-55fbf1cb5943
dominikdAtStampli commentedon Mar 10, 2025
Hey, are you sure about your answer? If so, why is there an API that allows creating dataset events? What is the purpose of creating those events if they are not triggering a downstream DAG that depends on a given dataset?
Also, is there a stable version of Airflow 3.0 where I could test if that was actually improved in the new release?
ferruzzi commentedon Mar 12, 2025
It looks like the code is commented indicating this is a known and intentional decision, along with a proposed solution that I don't understand yet.
https://github.com/apache/airflow/blob/2.10.5/airflow/datasets/manager.py#L167
Seems like we should be able to change the method to be
But I don't know. If the solution was that easy it would have been done by now; it would have been faster to fix than to write that .
There is an email on the dev-list with instructions to try out Airflow 3.0.0beta2, maybe you can use that to see if it has already been sorted out there?
Lee-W commentedon Nov 19, 2025
This was intentional and we're now tracking it through #56750