You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
map_index_template that produces numbers fails #71586
I have a dynamic mapped task that uses map_index_template to make it easier to distinguish tasks in the UI.
However, when the result of map_index_template is convertible to int, Airflow/Jinja2 does that, which then fails downstream in the code.
Example that triggers a failure: map_index_template="123"
Error:
TypeError: object of type 'int' has no len()
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1279 in run
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1695 in _render_map_index
What you think should happen instead?
The value should not be coerced into an int so that map_index_template results that look like numbers are valid.
Operating System
Debian 12 (but presumably irrelevant)
Deployment
Official Apache Airflow Helm Chart
Apache Airflow Provider(s)
No response
Versions of Apache Airflow Providers
No response
Official Helm Chart version
Not Applicable
Kubernetes Version
Not Applicable
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
I can confirm that the value produced by the template are strings. I've also tried adding | string to the template to force it to a string, but Jinja still forces a coercion to int. Adding some non-integer extra text to the template (e.g. map_index_template="id: {{ ... }}" works, but is an annoying workaround that doesn't add any additional value.
In this case, Jinja always attempts to render the value as a native object—in this instance, as an integer. If this option is not enabled, the issue does not arise. There is a relevant section on this in the Airflow documentation.
NativeEnvironment renders values according to Python literal rules. This is useful when a template should produce a list, dict, number, or boolean, but it also means a string that looks like a number, such as "42", can be rendered as the integer 42. Keep the default string rendering, use a callable template field, or add explicit quoting if the task needs the value to stay a string.
Using map_index_template="'{{ ... }}'" instead of map_index_template="{{ ... }}" should resolve the issue.
Hit this on 3.3.2 (task-sdk 1.3.1). We set render_template_as_native_obj=True for every DAG through a shared factory, and a mapped task labelled map_index_template="{{ task.file_id }}" (an int id) failed all 85 instances on its first production run.
Re whether it's a bug: quoting the template works, but a map index label can only ever be a string. _render_map_index is typed -> str | None, and SetRenderedMapIndex.rendered_map_index is str; with the len() removed, an int still fails there (Input should be a valid string). Native rendering can't produce a valid non-string label, so for this one template it only adds a failure mode.
It also fails late. The pre-execute render swallows the error and the post-execute render raises it, so the task's work completes and then the task is marked failed and retried.
Activity
Fix map_index_template producing numeric values in Task SDK (apache#7…
dondaum commentedon Sep 15, 2026
I assume this only occurs when the option to render fields as native Python objects is enabled, i.e.
render_template_as_native_obj=Trueis set:https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/operators.html#rendering-fields-as-native-python-objects
In this case, Jinja always attempts to render the value as a native object—in this instance, as an integer. If this option is not enabled, the issue does not arise. There is a relevant section on this in the Airflow documentation.
NativeEnvironment renders values according to Python literal rules. This is useful when a template should produce a list, dict, number, or boolean, but it also means a string that looks like a number, such as "42", can be rendered as the integer 42. Keep the default string rendering, use a callable template field, or add explicit quoting if the task needs the value to stay a string.
Using
map_index_template="'{{ ... }}'"instead ofmap_index_template="{{ ... }}"should resolve the issue.ngnnah commentedon Oct 9, 2026
Hit this on 3.3.2 (task-sdk 1.3.1). We set
render_template_as_native_obj=Truefor every DAG through a shared factory, and a mapped task labelledmap_index_template="{{ task.file_id }}"(an int id) failed all 85 instances on its first production run.Re whether it's a bug: quoting the template works, but a map index label can only ever be a string.
_render_map_indexis typed-> str | None, andSetRenderedMapIndex.rendered_map_indexisstr; with thelen()removed, an int still fails there (Input should be a valid string). Native rendering can't produce a valid non-string label, so for this one template it only adds a failure mode.It also fails late. The pre-execute render swallows the error and the post-execute render raises it, so the task's work completes and then the task is marked failed and retried.
+1 for the
str()in #71592.