Skip to content

map_index_template that produces numbers fails #71586

Description

@sweco-sedalh

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions