apache / apache/airflow

`map_index_template` that produces numbers fails

Open
#71,586 0 comments 0 reactions 0 assignees View on GitHub
area:dynamic-task-mapping kind:bug
Dominant language
Python
Stars
46.9k
Forks
17.8k
Avg merge
2d 9h
Merged PRs (30d)
472

Description

### 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)

Contributor guide

Open the contributing guide

Research direction

The failure is reported in airflow/sdk/execution_time/task_runner.py, in _render_map_index; start there and reproduce it with map_index_template="123". Trace the template result through rendering and add or locate the relevant test; done means numeric-looking results remain strings and the example no longer raises TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, data-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.