question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TaskGroup does not support dynamically generated tasks

See original GitHub issue

Apache Airflow version: 2.0 / master

Environment:

breeze

What happened:

Using this DAG:

from airflow.operators.bash import BashOperator
from airflow.operators.python import task
from airflow.models import DAG
from airflow.utils.task_group import TaskGroup

@task
def show():
    print("Cats are awesome!")

with DAG(
    "using_task_group",
    default_args={'owner': 'airflow'},
    start_date=days_ago(2),
    schedule_interval=None,
) as dag3:
    start_task = BashOperator(
        task_id="start_task",
        bash_command="echo start",
    )

    end_task = BashOperator(
        task_id="end_task",
        bash_command="echo end",
    )

    with TaskGroup(group_id="show_tasks") as tg1:
        previous_show = show()
        for _ in range(100):
            next_show = show()
            previous_show >> next_show
            previous_show = next_show

I get:

Broken DAG: [/files/dags/test.py] Traceback (most recent call last):
  File "/opt/airflow/airflow/models/baseoperator.py", line 410, in __init__
    task_group.add(self)
  File "/opt/airflow/airflow/utils/task_group.py", line 140, in add
    raise DuplicateTaskIdFound(f"Task id '{key}' has already been added to the DAG")
airflow.exceptions.DuplicateTaskIdFound: Task id 'show_tasks.show' has already been added to the DAG

If I remove the task group the task are generated as expected.

What you expected to happen:

I expect to be able to generate tasks dynamically using TaskGroup and task decoratos.

How to reproduce it:

Use the DAG from above.

Anything else we need to know:

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

7reactions
ahayasiccommented, Apr 29, 2021

@ssiddiqui-apixio I’m having the same problem on Airflow 2.0.2. Any chance of the Issue being reopened for a new solution?

1reaction
casassgcommented, Nov 12, 2020

Looking at @turbaszek code, that should address this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Airflow: Problem with creating dynamic task within TaskGroup
The problem arise when I tried to create task dynamically within TaskGroup . If I removed TaskGroup it worked fine.
Read more >
Dynamic Task Mapping — Airflow Documentation
Dynamic Task Mapping allows a way for a workflow to create a number of tasks at runtime based upon current data, rather than...
Read more >
Dynamic TaskGroup instanciation in Airflow 2.0
TaskGroup feature in Airflow 2.0 - Dynamic creation ... First catch : you can't create a Task or TaskGroup without being inside the...
Read more >
Create dynamic Airflow tasks | Astronomer Documentation
With the release of Airflow 2.3, you can write DAGs that dynamically generate parallel tasks at runtime. This feature, known as dynamic task...
Read more >
[GitHub] [airflow] turbaszek opened a new issue #12309
[GitHub] [airflow] turbaszek opened a new issue #12309: TaskGroup does not support dynamically generated tasks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found