Repository navigation
Dynamic Task Mapping skips tasks before upstream has started #28973
Description
Apache Airflow version
2.5.0
What happened
In some cases we are seeing dynamic mapped task being skipped before upstream tasks have started & the dynamic count for the task can be calculated. We see this both locally in a with the LocalExecutor & on our cluster with the KubernetesExecutor.
To trigger the issue we need multiple dynamic tasks merging into a upstream task, see the images below for example. If there is no merging the tasks run as expected. The tasks also need to not know the number of dynamic tasks that will be created on DAG start, for example by chaining in an other dynamic task output.
If the DAG, task, or upstream tasks are cleared the skipped task runs as expected.
The issue exists both on airflow 2.4.x & 2.5.0.
Happy to help debug this further & answer any questions!
What you think should happen instead
The tasks should run after upstream tasks are done.
How to reproduce
The following code is able to reproduce the issue on our side:
from datetime import datetime
from airflow import DAG
from airflow.decorators import task
from airflow.utils.task_group import TaskGroup
from airflow.operators.empty import EmptyOperator
# Only one chained tasks results in only 1 of the `skipped_tasks` skipping.
# Add in extra tasks results in both `skipped_tasks` skipping, but
# no earlier tasks are ever skipped.
CHAIN_TASKS = 1
@task()
def add(x, y):
return x, y
with DAG(
dag_id="test_skip",
schedule=None,
start_date=datetime(2023, 1, 13),
) as dag:
init = EmptyOperator(task_id="init_task")
final = EmptyOperator(task_id="final")
for i in range(2):
with TaskGroup(f"task_group_{i}") as tg:
chain_task = [i]
for j in range(CHAIN_TASKS):
chain_task = add.partial(x=j).expand(y=chain_task)
skipped_task = (
add.override(task_id="skipped").partial(x=i).expand(y=chain_task)
)
# Task isn't skipped if final (merging task) is removed.
init >> tg >> finalOperating System
MacOS
Versions of Apache Airflow Providers
This can be reproduced without any extra providers installed.
Deployment
Official Apache Airflow Helm Chart
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 Jan 16, 2023
Thanks for opening your first issue here! Be sure to follow the issue template!
uranusjr commentedon Jan 18, 2023
Can you try if #28592 fixed this?
ephraimbuddy commentedon Jan 18, 2023
Working for me in the current main but the graph is not displaying(cc @bbovenzi ).
bbovenzi commentedon Jan 18, 2023
Did it not load at all? Or just incorrectly? I fixed one graph issue yesterday: #28993
inytar commentedon Jan 18, 2023
I tried this both in
mainand #28592 but still see the same issue. Also as @ephraimbuddy I don't see the graph either, but I guess that's an other issue.ephraimbuddy commentedon Jan 19, 2023
@inytar , it works for me in the current main. No skipping. What are your other settings like?
@bbovenzi , it doesn't come up on the graph view in the current main
bbovenzi commentedon Jan 19, 2023
Oh I see. I have a fix for the UI part here: #29042
inytar commentedon Jan 19, 2023
I've seen the issue on different settings/environments:
airflow standaloneIt seems to me like some kind of race condition, could you try upping the number of
CHAIN_TASKS? If I set this to 1 I only see one task being skipped, if I set it to 2 I see both task being skipped.I've updated the code a bit to add a workaround. This just adds two empty tasks before the merge, when this is done the tasks aren't skipped anymore (also useful for anyone else that might hit this):
I'm OoO till Monday Jan 30th, so I won't be able to help much till then. When I'm back I'm happy to test, ect!
darkfennertrader commentedon Mar 31, 2023
Hello,
just to let you know that the problem still exists with multiple dynamic tasks in cascade. I solved the issue using an empty operator.
Airflow 2.5.2 (using the official docker-compose file)
Celery Executor
OS: Ubuntu 22.04
python version: 3.10.6
jose-workpath commentedon Apr 4, 2023
I also have this error on Airflow
2.5.3.I found out that it happens when 2 dynamically mapped tasks have a dependency with each other and the child task of the last mapped task has another parent task. ie in a DAG like this:
graph LR A["A (mapped task)"] --> B["B (mapped task)"] --> D C --> DThe mapped task
Bwill always get skipped, and of course any child task of it.In my case, I can not do what @darkfennertrader suggested because I use the result of the first mapped task as a parameter of the next mapped task.
I created a simple DAG to reproduce the error I'm getting:
uranusjr commentedon Apr 4, 2023
Thanks for the investigation and the reproduction, that’s great help. I’ll find some time to check if I can find the issue later this week.
uranusjr commentedon Apr 10, 2023
First finding:
d_wrapis skipped becauseb_make_it_doubleis not expanded, and the unexpanded task is marked as skipped. Next I need to find out whyb_make_it_doubleis marked as skipped. This happens surprisingly early in scheduling, even beforea_add_them_togetheris actually run!? And more weird I can yet find what causesb_make_it_doubleto be skipped (no relevant logs).uranusjr commentedon Apr 14, 2023
Update: My attempt to induce the issue with an extremely simplified scheduler (calling
task_instance_scheduling_decisionsrepeatedly) does not work; things all run as expected. This leads me to guess the issue may be in the mini scheduler, not the main scheduler loop.uranusjr commentedon Apr 14, 2023
Yup, issue’s gone if I set
schedule_after_task_execution = false. This should greatly narrow down the possible causes.