Repository navigation
Rendering custom map index before task is run. #39118
Description
Activity
- addedkind:featureFeature RequestsFeature Requestsneeds-triagelabel for new issues that we didn't triage yetlabel for new issues that we didn't triage yet
on Apr 18, 2024 This is a follow on from #39065 with a narrower scope (just rendering while the task is running) as the other items in that issue have been or will be resolved by the other issues/PRs referenced.
- added and removedneeds-triagelabel for new issues that we didn't triage yetlabel for new issues that we didn't triage yet
on Apr 18, 2024 related : #39092
@tomrutter Would you like to be assigned?
Given the current design (using a task's
contextobject means we have to wait for the task to start running), I think this might be trickier than meets the eye.since we can define at operator definition the field
map_index_template="{{ task.op_kwargs['date'] }}",, it can be render by the webserverHappy to be assigned, but if someone has a clear idea, happy for that to go ahead too.
I’m guessing the big issue with rendering on the webserver is picking up the context added by the task. I’d start with that for now though with failover to rendered value from the task if that exists.
Hi @tomrutter are you working on ?
since we can define at operator definition the field
map_index_template="{{ task.op_kwargs['date'] }}",, it can be render by the webserverthis solution does not work if the task is run in a
PythonVirtualEnvtask. The following wont work:@task.virtualenv( requirements=["inspire-schemas"], system_site_packages=False, map_index_template="{{task.op_kwargs['date']}}", )`Is there a workaround for this specific case?
I'm not sure, and I'm not sure if it's safe to handle the rendering on the webserver. @uranusjr Do you think it will be straightforward to implement named mapped tasks before the task completes in Airflow 3?
Any news on it?
I thought I already commented on this, but maybe I was just dreaming, or the message is lost in the ether. I don’t think it’s really viable to render anywhere else than in the worker. I’m thinking, maybe we should just make the map index on UI editable, so the user can manually set the value to anything they want? Either before or after the task is run.
I'd be happy with an even simpler option: let me refer to a parameter passed to the task/operator in the template, and use that before the execute method is called. This way I'd see the named mapping as soon as my task/operator starts running.
At the moment I do not see any way to refer to a passed parameter to a classic operator. In case of a @task I can do this, but still it does not get evaluated until the task finished: map_index_template='{{ task.op_kwargs["number"] }}'
Reacted by Sergio Tobal and Kanto(칸토)- marked Dynamic Task Mapping – map_index_template value is not rendered in the UI during running state #56722 as a duplicate of this issue
on Oct 16, 2025 One solution: #57208
- unmarked Dynamic Task Mapping – map_index_template value is not rendered in the UI during running state #56722 as a duplicate of this issue
on Oct 26, 2025 - added a commit that references this issue
on Oct 26, 2025
Description
The map_index_template field on a task is used to render a custom name for each individual sub task in a mapped task. It is generated by rendering the task context on the jinja template provided. This rendering happens after the task is completed so it does not appear during or before the task run. The new feature would be to attempt to render and display this field before the task is run (using the context available at the time), with a suitable failback if this is not possible with the context values available.
Use case/motivation
It would be useful to see the custom map index during task runs, when the context information to do so is available. The mapped task index can be used to provide human readable information to distinguish the mapped tasks from one another and would make it easier to track task progress during a dag run.
Related issues
Various issues and PRs have dealt with displaying the custom map index when the task fails.
#39065, #39092, #38902, #39087
Are you willing to submit a PR?
Code of Conduct