You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "sweco-sedalh (via GitHub)" <gi...@apache.org> on 2026/08/14 05:16:44 UTC

[I] `map_index_template` that produces numbers fails [airflow]

sweco-sedalh opened a new issue, #71586:
URL: https://github.com/apache/airflow/issues/71586

   ### Under which category would you file this issue?
   
   Airflow Core
   
   ### Apache Airflow version
   
   3.2.0
   
   ### What happened and how to reproduce it?
   
   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.
   
   ### 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: commits-unsubscribe@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `map_index_template` that produces numbers fails [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil closed issue #71586: `map_index_template` that produces numbers fails
URL: https://github.com/apache/airflow/issues/71586


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `map_index_template` that produces numbers fails [airflow]

Posted by "ngnnah (via GitHub)" <gi...@apache.org>.
ngnnah commented on issue #71586:
URL: https://github.com/apache/airflow/issues/71586#issuecomment-6078848464

   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.
   
   +1 for the `str()` in #71592.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] `map_index_template` that produces numbers fails [airflow]

Posted by "dondaum (via GitHub)" <gi...@apache.org>.
dondaum commented on issue #71586:
URL: https://github.com/apache/airflow/issues/71586#issuecomment-5677551003

   I assume this only occurs when the option to render fields as native Python objects is enabled, i.e. `render_template_as_native_obj=True` is 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 of `map_index_template="{{ ... }}"` should resolve the issue.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org