Skip to content

Explicitly convert map_index to str - #71592

Merged
kaxil merged 2 commits into
apache:mainfrom
Prajwal7842:prajwal7842/71586
Oct 13, 2026
Merged

kaxil merged 2 commits into
apache:mainfrom
Prajwal7842:prajwal7842/71586

Conversation

@Prajwal7842

@Prajwal7842 Prajwal7842 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Previous: Dynamic task map index was using jinja's native env, so any numeric string like "123" was being coverted to int and subsequently failing.

Fix: Use jinja native render_template_as_native() function to case types correctly followed by an explicit conversion to str if it is not None (as suggested by Kaxil in the PR comment).


closes: #71586


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@jroachgolf84 jroachgolf84 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I like the fix.

@Prajwal7842

Copy link
Copy Markdown
Contributor Author

Hi @amoghrajesh Can you help with the review for this fix. Thank you.

@dondaum

dondaum commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Hi everyone, I’m not really convinced that #71586 is actually an issue.
Could you please take a look at my comments here: #71586 (comment)
I could be wrong, of course, but I don't think any changes are needed here.

@sweco-sedalh

Copy link
Copy Markdown

@dondaum I'd say it's definitely an issue, since we're at least two who've ran into it. I haven't had time to test your workaround to quote the value, but I'd expect it to work, however that's still only a workaround. Even if it was included in the docs it's not what I as a DAG-author would expect, and therefore would probably miss. Much better to have a fix that makes this behave as you'd expect (producing a string under any condition, since that's all it ever needs to be).

@kevinhongzl

Copy link
Copy Markdown
Contributor

Hi everyone, I’m not really convinced that #71586 is actually an issue. Could you please take a look at my comments here: #71586 (comment) I could be wrong, of course, but I don't think any changes are needed here.

Wrapping the template expression within single quotes could work, but the rendering result may differ depending on render_template_as_native_obj (e.g. '12.0' vs. 12.0). And that's exactly what render_template_as_native_obj is testing. So +1 for this pr!

@kaxil

kaxil commented Oct 13, 2026

Copy link
Copy Markdown
Member

Thanks, LGTM. Could you update the title and description before merge? They still describe the earlier render_template_as_native() plus str() approach, but the code now renders the label with the Dag's sandboxed string environment. A title like "Fix map_index_template failing for numeric-looking labels with render_template_as_native_obj" reads better in the changelog.

One user-visible change is worth a line in the description: on Dags with render_template_as_native_obj=True, a quoted template such as "'{{ ti.try_number }}'" (the workaround suggested on #71586) now shows the quotes in the label, the same as on default Dags.

@kaxil
kaxil merged commit 47d929c into apache:main Oct 13, 2026
108 of 109 checks passed
@kaxil kaxil added this to the Airflow 3.4.0 milestone Oct 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-4-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-4-test PR Link

vatsrahul1001 pushed a commit that referenced this pull request Oct 18, 2026
…ls with `render_template_as_native_obj` (#71592) (#74978)

* Explicitly convert map_index to str

* Address comments
(cherry picked from commit 47d929c)

Co-authored-by: Prajwal Agarwal <34996624+Prajwal7842@users.noreply.github.com>
vatsrahul1001 pushed a commit that referenced this pull request Oct 20, 2026
…ls with `render_template_as_native_obj` (#71592) (#74978)

* Explicitly convert map_index to str

* Address comments
(cherry picked from commit 47d929c)

Co-authored-by: Prajwal Agarwal <34996624+Prajwal7842@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

map_index_template that produces numbers fails

7 participants