GitHub user pykenny edited a comment on the discussion: MappedTaskGroup without 
taskflow

>From documentation it's not recommended to use `MappedTaskGroup` directly 
>([reference](https://github.com/apache/airflow/blob/47e4fe6926fda9ffbd595a0985f05c22e272a61f/task-sdk/src/airflow/sdk/definitions/taskgroup.py#L612-L613))
> so I don't think it's not a good idea.

If you want to avoid decorator syntax in DAG definition, it may be better to 
wire task inputs/outputs just at task level instead of using a mapped task 
group. Looks a bit redundant but I think it is logically equivalent to the 
original one. What about giving this adjustment a try?

```python
...
from airflow.utils.task_group import TaskGroup

...

with DAG(
        dag_id="dag_group_DTM",
        start_date=today("UTC").add(days=-1),
        schedule=timedelta(days=1),
):

    first = PythonOperator(
        task_id="first",
        python_callable=lambda : [1, 10, 20, 30]
    )

    def sleep(duration):
        # It's recommended to place module imports in the task function 
(subroutine),
        # so that all required imports only happens when the task gets run.
        import time

        time.sleep(duration)

    with TaskGroup(group_id="group_1"):
        a = PythonOperator.partial(task_id="a", 
python_callable=sleep).expand(duration=duration.output)
        b = PythonOperator.partial(task_id="b", 
python_callable=sleep).expand(duration=duration.output)
        c = PythonOperator.partial(task_id="a", 
python_callable=sleep).expand(duration=duration.output)

        a >> b >> c
```

GitHub link: 
https://github.com/apache/airflow/discussions/50297#discussioncomment-13262214

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to