Skip to content

Stop rendering embedded blueprint source as Jinja - #88

Open
jlaneve wants to merge 1 commit into
mainfrom
literal-step-context
Open

jlaneve wants to merge 1 commit into
mainfrom
literal-step-context

Conversation

@jlaneve

@jlaneve jlaneve commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

A blueprint whose source file contains a Jinja string fails every task it builds. For example, map_index_template="{{ task.prompt.splitlines()[0] }}" gives UndefinedError: '..._PythonDecoratedOperator object' has no attribute 'prompt' on the first task, even one that never uses that template. Blueprint adds the step config, the blueprint source and the DAG args to each task's template_fields so the Rendered Template tab shows them, and Airflow renders those fields as Jinja when the task runs. Each value is now wrapped in a Jinja raw block, so it renders back to the exact text.

Call-stack diff

  build_all_airflow_dags()
  └─ Builder.build()
     └─ Builder._render_step()
        ├─ blueprint.render(config)              # unchanged
        └─ Builder._inject_step_context()
+          ├─ _jinja_literal(step_yaml)
+          ├─ _jinja_literal(source_code)
+          └─ _jinja_literal(dag_args_yaml)

Unchanged: the three fields stay in template_fields with the same renderers. A config value that a blueprint passes into an operator argument, such as bash_command: "echo {{ ds }}", still renders there.

  • Where I am least sure. _jinja_literal splits every {% in the text, so an {% endraw %} inside a blueprint's source cannot close the raw block early. I checked it against plain, sandboxed (with trim_blocks and lstrip_blocks) and native Jinja environments. Until Airflow renders them, task.blueprint_step_code and the other two attributes hold the wrapped text, so anything that reads them directly sees the raw markup.
  • What I chose against. Taking the fields out of template_fields also stops the rendering, but drops them from the Rendered Template tab.
  • embed_source is not involved. It controls only default_args["blueprint_source"] for the YAML tab, which is not a template field, and it never turned off these per-task fields.
  • What it cost. 9 new tests in tests/test_builder.py, all failing before the fix. pytest tests/ --ignore=tests/integration: 445 passed. ruff check, ruff format --check and ty check pass. I did not run the integration tests, which need the Astro CLI. Found with 0.5.0 on Airflow 3.3.2; the tests reproduce it on 3.0.3.

Blueprint adds blueprint_step_config, blueprint_step_code and
blueprint_dag_args to each task's template_fields so the Rendered
Template tab shows them. Airflow renders these fields as Jinja when the
task runs, so a blueprint whose source file contains a template string
such as "{{ task.prompt }}" failed every task it built.

Wrap each value in a Jinja raw block before it goes on the task. Every
"{%" in the text gets split so an "endraw" tag inside the source cannot
close the block early. The rendered value is the original text, and
config values that operators use as templates still render in their
own fields.
@jlaneve
jlaneve requested a review from a team as a code owner October 5, 2026 04:17
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Claude finished @jlaneve's task in 2s —— View job


I'll analyze this and get back to you.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants