kaxil commented on code in PR #71592:
URL: https://github.com/apache/airflow/pull/71592#discussion_r4050846735
##########
task-sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -2259,7 +2260,7 @@ def _render_map_index(context: Context, ti:
RuntimeTaskInstance, log: Logger) ->
return None
log.debug("Rendering map_index_template", template_length=len(template))
jinja_env = ti.task.dag.get_template_env()
- rendered_map_index = jinja_env.from_string(template).render(context)
+ rendered_map_index =
render_template_to_string(jinja_env.from_string(template), context)
Review Comment:
This forces string-mode rendering (`native=False`, `"".join(nodes)` in
`render_template`), but the template is compiled by whatever
`dag.get_template_env()` returns. That's a jinja2 `NativeEnvironment` when
`render_template_as_native_obj=True`. `NativeCodeGenerator` skips wrapping
output nodes in `str()`, so a template like `map_index_template="index-{{
ti.try_number }}"` yields `['index-', 1]` from `root_render_func`, and
`"".join(['index-', 1])` raises `TypeError: sequence item 1: expected str
instance, int found`. Even a bare `"{{ ti.try_number }}"` crashes the same way,
turning an otherwise-successful task into a failed one.
The new test only covers a bare literal `"123"` (no `{{ }}`). That stays a
plain-text `str` node regardless of which code generator compiled it, so it
doesn't catch this case: a label combined with a mapped or try index, usually
an `int`.
A fix that holds under both env modes: always render through the native path
(`render_template_as_native`) and `str()`-cast the result if it isn't `None`.
`native_concat` already does per-node `str()` coercion when there's more than
one node, and passes through an already-`str` single-node result untouched. The
only missing piece is the final cast.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]