<h3 dir="auto">Description</h3>
<p dir="auto">Adding a user defined, small text <code class="notranslate">label</code> field to (mapped) task instances, which would appear in the UI</p>
<h3 dir="auto">Use case/motivation</h3>
<p dir="auto">Currently it is difficult to differentiate between mapped tasks in both the <code class="notranslate">Grid view</code> and the <code class="notranslate">Browse &gt; Task Instances</code> view. It requires a lot of hunting and pecking into either the parent XCOM to find what you need, or individually clicking through the Rendered task view.</p>
<p dir="auto">It would be helpful to be able to mark tasks with metadata at runtime in some fashion, to distinguish in the UI</p>
<h3 dir="auto">Related issues</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Are you willing to submit a PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>
<h3 dir="auto">Description</h3>
<p dir="auto">Airflow currently exposes <code class="notranslate">map_index</code> 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.</p>
<p dir="auto">To see the problem, consider a dag that sends email to a list of users which is generated at runtime:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="with DAG(...) as dag:

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

    BashOperator.partial(
        task_id=&quot;send_email&quot;,
        bash_command=dedent(
            &quot;&quot;&quot;
            cat &lt;&lt;- EOF | tee | mailx -s &quot;your account&quot; $EMAIL
            Dear $NAME,
                Your account status is $STATUS.
            EOF
            &quot;&quot;&quot;
        ),
    ).expand(env=get_account_status())"><pre class="notranslate"><span class="pl-k">with</span> <span class="pl-v">DAG</span>(...) <span class="pl-k">as</span> <span class="pl-s1">dag</span>:

    <span class="pl-en">@<span class="pl-s1">dag</span>.<span class="pl-s1">task</span></span>
    <span class="pl-k">def</span> <span class="pl-en">get_account_status</span>():
        <span class="pl-k">return</span> [
            {
                <span class="pl-s">"NAME"</span>: <span class="pl-s">"Wintermute"</span>,
                <span class="pl-s">"EMAIL"</span>: <span class="pl-s">"wintermute@tessier-ashpool.com"</span>,
                <span class="pl-s">"STATUS"</span>: <span class="pl-s">"active"</span>,
            },
            {
                <span class="pl-s">"NAME"</span>: <span class="pl-s">"Hojo"</span>,
                <span class="pl-s">"EMAIL"</span>: <span class="pl-s">"ops@research.shinra.com"</span>,
                <span class="pl-s">"STATUS"</span>: <span class="pl-s">"delinquent"</span>,
            },
        ]

    <span class="pl-v">BashOperator</span>.<span class="pl-en">partial</span>(
        <span class="pl-s1">task_id</span><span class="pl-c1">=</span><span class="pl-s">"send_email"</span>,
        <span class="pl-s1">bash_command</span><span class="pl-c1">=</span><span class="pl-en">dedent</span>(
            <span class="pl-s">"""</span>
<span class="pl-s">            cat &lt;&lt;- EOF | tee | mailx -s "your account" $EMAIL</span>
<span class="pl-s">            Dear $NAME,</span>
<span class="pl-s">                Your account status is $STATUS.</span>
<span class="pl-s">            EOF</span>
<span class="pl-s">            """</span>
        ),
    ).<span class="pl-en">expand</span>(<span class="pl-s1">env</span><span class="pl-c1">=</span><span class="pl-en">get_account_status</span>())</pre></div>
<p dir="auto">Notice that in the grid view, it's not obvious which task goes with which user:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5834582/163418431-3180a29d-b9c0-4bbc-9a80-05ad5e4f34e7.png"><img width="1106" alt="Screen Shot 2022-04-14 at 8 56 09 AM" src="https://user-images.githubusercontent.com/5834582/163418431-3180a29d-b9c0-4bbc-9a80-05ad5e4f34e7.png" style="max-width: 100%;"></a></p>
<h3 dir="auto">Use case/motivation</h3>
<p dir="auto">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.</p>
<p dir="auto">In cases where the user provides no names, perhaps we can generate some.  For instance, this expansion generates four instances.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="BashOperator.partial(task_id=&quot;greet&quot;).expand(
    bash_command=[&quot;echo hello $USER&quot;, &quot;echo goodbye $USER&quot;],
    env=[{&quot;USER&quot;: &quot;foo&quot;}, {&quot;USER&quot;: &quot;bar&quot;}],
)"><pre class="notranslate"><span class="pl-v">BashOperator</span>.<span class="pl-en">partial</span>(<span class="pl-s1">task_id</span><span class="pl-c1">=</span><span class="pl-s">"greet"</span>).<span class="pl-en">expand</span>(
    <span class="pl-s1">bash_command</span><span class="pl-c1">=</span>[<span class="pl-s">"echo hello $USER"</span>, <span class="pl-s">"echo goodbye $USER"</span>],
    <span class="pl-s1">env</span><span class="pl-c1">=</span>[{<span class="pl-s">"USER"</span>: <span class="pl-s">"foo"</span>}, {<span class="pl-s">"USER"</span>: <span class="pl-s">"bar"</span>}],
)</pre></div>
<p dir="auto">The friendliest way would be to use the requested feature name each task:</p>
<ul dir="auto">
<li><code class="notranslate">hi_foo</code></li>
<li><code class="notranslate">hi_bar</code></li>
<li><code class="notranslate">bye_foo</code></li>
<li><code class="notranslate">bye_bar</code></li>
</ul>
<p dir="auto">As it is, the user will see:</p>
<ul dir="auto">
<li><code class="notranslate">1</code></li>
<li><code class="notranslate">2</code></li>
<li><code class="notranslate">3</code></li>
<li><code class="notranslate">4</code></li>
</ul>
<p dir="auto">But if the user doesn't give names, maybe we should generate some names for them:</p>
<ul dir="auto">
<li><code class="notranslate">bash_command_1_env_1</code></li>
<li><code class="notranslate">bash_command_1_env_2</code></li>
<li><code class="notranslate">bash_command_2_env_1</code></li>
<li><code class="notranslate">bash_command_2_env_2</code></li>
</ul>
<p dir="auto">I don't know.  I'm creating this issue so we have a place to discuss it.</p>
<h3 dir="auto">Related issues</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Are you willing to submit a PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>