vsilviaMO opened a new issue, #50286: URL: https://github.com/apache/airflow/issues/50286
### Apache Airflow version 3.0.0 ### If "Other Airflow 2 version" selected, which one? _No response_ ### What happened? Per the documentation here, https://airflow.apache.org/docs/apache-airflow/stable/authoring-and-scheduling/dynamic-task-mapping.html#named-mapping, custom mapped task naming should work essentially the same as in Airflow 2.10.0. I have this task configured: `from airflow.sdk import get_current_context @task(task_id="transform_load_data", max_active_tis_per_dagrun=4, map_index_template="{{ custom_name }}", retries=3, retry_delay=timedelta(seconds=120), on_retry_callback=sl.task_retry_alert, on_failure_callback=sl.task_failure_alert) def tl_cinema(table_map: dict, dir_map: dict, s3_config: dict, sf_config: dict, s3_file: str): """ Task to perform end-to-end transformation and load of a single file at a time """ # Dynamic task naming context = get_current_context() context["custom_name"] = s3_file` In Airflow 2.10.0, the import is different (and this doesn't work in 3.0.0): `from airflow.operators.python import get_current_context` But I get the expected result - instead of a numerically-assigned index, the mapped task index is a more meaningful and useful value.  In Airflow 3.0.0 (and 3.0.1rc1), the task naming doesn't appear to work. If the "Map Index" column is supposed to be replaced with the map_index_template as in 2.10.0, it is not working:  I do see one error in the task execution that indicates the custom_name value is not defined: `[2025-05-06, 15:35:34] ERROR - Task failed with exception: source="task" UndefinedError: 'custom_name' is undefined File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 847 in run File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1146 in _render_map_index File "/home/airflow/.local/lib/python3.12/site-packages/structlog/_native.py", line 146 in meth File "/home/airflow/.local/lib/python3.12/site-packages/jinja2/runtime.py", line 859 in _fail_with_undefined_error` But I'm not sure what the difference is between how I use the `custom_name` variable and how the example documentation uses the `my_variable` variable for custom mapped task naming. Additionally, this error only shows up in 3.0.1rc1. In 3.0.0, there is no error in the logs, but the result is the same - no custom mapped task name. ### What you think should happen instead? The MAP INDEX column of the UI should be replaced with the custom_name variable I set in the task, as it works in Airflow 2.10.0 ### How to reproduce Deploy via sample docker-compose.yaml file with default values for concurrency. Create a DAG with a task that can run concurrently (say, "process" a file for 60 seconds), set the get the context and set a variable within the context and then assign that variable to the map_index_template value in the task definition. ### Operating System Debian GNU/Linux 12 (bookworm) ### Versions of Apache Airflow Providers _No response_ ### Deployment Docker-Compose ### Deployment details _No response_ ### Anything else? _No response_ ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
