Issue 1:
Description

Background

The new Dynamic Task Mapping feature adds the attribute map_index to the TaskInstance class. When viewing information for a single mapped task instance, you must select based on this map_index, e.g. an integer value 0, 1, 2, ... n.

However, task instances can be mapped based on an iterable data type using the .expand() - using a slightly modified Airflow Simple Mapping example, on a list:

added_values = add_one.expand(x=['truck', 'car', 'bicycle'])

It is a challenge to view the log for the task instance add_one that used the input 'truck'. In the UI, there is no indication of the element at that index, only the index. In practice, you must click through all task instances [0, 1, 2] to find the truck log.

Proposal

Parameter for TaskInstance that maps map_index to a value with meaning i.e. the list element at index map_index

UI updated to show list element, if parameter is provided

Use case/motivation

I would like the UI to indicate the input element value for each mapped task instance, not the index map_index. This will make it easier to navigate mapped task instances.

Related issues

No response

Are you willing to submit a PR?

Yes I am willing to submit a PR!

Code of Conduct

I agree to follow this project's Code of Conduct

Issue 2:
Description

Airflow currently exposes map_index to the user as a way of distinguishing between tasks in an expansion. The index is unlikely to be meaningful to the user. They probably have their own label for this action. I'm requesting that we allow them to add that label.

To see the problem, consider a dag that sends email to a list of users which is generated at runtime:

with DAG(...) as dag:

@dag.task
def get_account_status():
return [
{
"NAME": "Wintermute",
"EMAIL": "wintermute@tessier-ashpool.com",
"STATUS": "active",
},
{
"NAME": "Hojo",
"EMAIL": "ops@research.shinra.com",
"STATUS": "delinquent",
},
]

BashOperator.partial(
task_id="send_email",
bash_command=dedent(
"""
cat <<- EOF | tee | mailx -s "your account" $EMAIL
Dear $NAME,
Your account status is $STATUS.
EOF
"""
),
).expand(env=get_account_status())

Notice that in the grid view, it's not obvious which task goes with which user:

Use case/motivation

I'd like to be able to explicitly assign a name to each expanded task, that way I can later go look at the right one. I would like this name to be used (when available) anywhere that the user interacts with the expanded task.

In cases where the user provides no names, perhaps we can generate some. For instance, this expansion generates four instances.

BashOperator.partial(task_id="greet").expand(
bash_command=["echo hello $USER", "echo goodbye $USER"],
env=[{"USER": "foo"}, {"USER": "bar"}],
)

The friendliest way would be to use the requested feature name each task:

hi_foo

hi_bar

bye_foo

bye_bar

As it is, the user will see:

1

2

3

4

But if the user doesn't give names, maybe we should generate some names for them:

bash_command_1_env_1

bash_command_1_env_2

bash_command_2_env_1

bash_command_2_env_2

I don't know. I'm creating this issue so we have a place to discuss it.

Related issues

No response

Are you willing to submit a PR?

Yes I am willing to submit a PR!

Code of Conduct

I agree to follow this project's Code of Conduct