Skip to content

Dynamic Mapped Task Group does not pack single mapped tasks in list #69036

Description

@Desdroid

Under which category would you file this issue?

Airflow Core

Apache Airflow version

3.2.2

What happened and how to reproduce it?

The DAG given below has inconsistent return values for the task group. If the group is only mapped once it will not pack the results in a list as it should for DTM.

If you start it with a list with a single item in it e.g. ['14'], consume_dtm will receive it unpacked and print e.g. 1 and then 4.
If the list contains multiple items e.g. ['15', '23'], they will all be packed in lists and therefore printed e.g. '15' and '23'

iirc this worked fine in 3.1.5

from airflow.sdk import dag, task, task_group


@dag
def dtm_return_value(some_input: list = ()):

    @task
    def convert_dag_param(a):
        return a

    @task
    def do_something(a):
        return a

    @task_group
    def group(a):
        test = do_something(a)
        return {"test": test}

    @task
    def consume_dtm(dtm_result):
        for res in dtm_result:
            print(res)

    result = group.expand(a=convert_dag_param(some_input))
    consume_dtm(result["test"])


instance = dtm_return_value()

What you think should happen instead?

It seems like the return value of the mapped task group gets unpacked if we have only 1 mapped task instance.
The return value should consistently be packed (result of a mapped task must always be a list)

Operating System

No response

Deployment

Official Apache Airflow Helm Chart

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

No response

Official Helm Chart version

1.22.0 (latest released)

Kubernetes Version

No response

Helm Chart configuration

No response

Docker Image customizations

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions