Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_leaves calculation for teardown in nested group #36456

Merged
merged 1 commit into from Dec 27, 2023

Conversation

dstandish
Copy link
Contributor

@dstandish dstandish commented Dec 27, 2023

Resolves #36345

When arrowing group >> task, the "leaves" of group are connected to task. When calculating leaves in the group, teardown tasks are ignored, and we recurse upstream to find non-teardowns.

What was happening, and what this fixes, is you might recurse to a work task that already has another non-teardown downstream in the group. In that case you should ignore the work task (because it already has a non-teardown descendent).

Before:

image

After:

image

Code:

with DAG(dag_id="s_t_dag") as dag:

    @task
    def test_task():
        print("Hello world!")

    @task_group
    def inner():
        inner_start = EmptyOperator(task_id="start")
        inner_end = EmptyOperator(task_id="end")

        test_task_r = test_task.override(task_id="work")()
        inner_start >> test_task_r >> inner_end.as_teardown(setups=inner_start)

    @task_group
    def outer():
        outer_work = EmptyOperator(task_id="work")
        inner_group = inner()
        inner_group >> outer_work

    dag_start = EmptyOperator(task_id="dag_start")
    dag_end = EmptyOperator(task_id="dag_end")
    dag_start >> outer() >> dag_end

When arrowing `group` >> `task`, the "leaves" of `group` are connected to `task`. When calculating leaves in the group, teardown tasks are ignored, and we recurse upstream to find non-teardowns.

What was happening, and what this fixes, is you might recurse to a work task that already has another non-teardown downstream in the group.  In that case you should ignore the work task (because it already has a non-teardown descendent).

Resolves apache#36345
@potiuk
Copy link
Member

potiuk commented Dec 27, 2023

Nice :)

@potiuk potiuk added this to the Airflow 2.8.1 milestone Dec 27, 2023
@dstandish dstandish merged commit 949fc57 into apache:main Dec 27, 2023
52 checks passed
@dstandish dstandish deleted the fix-nested-setup-teardown-dep branch December 27, 2023 21:10
@ephraimbuddy ephraimbuddy added the type:bug-fix Changelog: Bug Fixes label Jan 10, 2024
ephraimbuddy pushed a commit that referenced this pull request Jan 11, 2024
When arrowing `group` >> `task`, the "leaves" of `group` are connected to `task`. When calculating leaves in the group, teardown tasks are ignored, and we recurse upstream to find non-teardowns.

What was happening, and what this fixes, is you might recurse to a work task that already has another non-teardown downstream in the group.  In that case you should ignore the work task (because it already has a non-teardown descendent).

Resolves #36345

(cherry picked from commit 949fc57)
abhishekbhakat pushed a commit to abhishekbhakat/my_airflow that referenced this pull request Mar 5, 2024
When arrowing `group` >> `task`, the "leaves" of `group` are connected to `task`. When calculating leaves in the group, teardown tasks are ignored, and we recurse upstream to find non-teardowns.

What was happening, and what this fixes, is you might recurse to a work task that already has another non-teardown downstream in the group.  In that case you should ignore the work task (because it already has a non-teardown descendent).

Resolves apache#36345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup/Teardown in nested Task Groups creating unwanted dependencies with downstream tasks
3 participants