potiuk opened a new pull request, #76244:
URL: https://github.com/apache/airflow/pull/76244
The TaskFlow decorators that build their main field from the function's
return value (`@task.bash`, `@task.sql`, `@task.analytics`,
`@task.kubernetes_cmd` and the six common.ai decorators `@task.llm`,
`@task.agent`, `@task.llm_sql`, `@task.llm_branch`, `@task.llm_file_analysis`,
`@task.llm_schema_compare`) called `self.render_template_fields(context)`
inside `execute()` to render that returned value. The task runner has already
rendered every template field once before `execute()`, so that call rendered
all the other template fields (`env`, `cwd`, `op_args`, `op_kwargs`,
`parameters`, `system_prompt`, ...) a second time. A value that came out of the
first pass containing `{{ ... }}` was rendered again, which `BashOperator` and
the other plain operators never do.
This renders only the returned value (`self.bash_command =
self.render_template(self.bash_command, context)` and the equivalent for `sql`,
`queries`, the generated pod command and `prompt`), the same approach as
#71402. The returned value is still rendered as before, including
`template_ext` file lookup. `@task.kubernetes_cmd` also rendered all fields
once more before calling the function; that call is dropped too.
The common.ai docs did not say that the returned prompt is rendered as a
template, and the ticket-triage example formatted the ticket text into it with
an f-string. `llm.rst` now explains it and shows how to reference a function
argument by name in the returned template, and the example uses that.
Changes:
- Render only the returned value in the 10 decorators (11 call sites, 4
providers).
- A test per decorator that renders the fields once, as the task runner
does, and checks that other fields keep their rendered value while the returned
value is rendered.
- A common.ai test that an argument referenced in the returned prompt is
inserted as is.
- The kubernetes decorator test helper renders the fields before
`execute()`, as at runtime.
- Changelog notes for the four providers; `llm.rst` and
`example_llm_analysis_pipeline.py` updated.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Opus 5
Generated-by: Claude Opus 5 following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]