Skip to content

Pass runtime values to example Dag shell commands through env - #73787

Merged
potiuk merged 4 commits into
apache:mainfrom
potiuk:example-dag-env-passing
Oct 19, 2026
Merged

potiuk merged 4 commits into
apache:mainfrom
potiuk:example-dag-env-passing

Conversation

@potiuk

@potiuk potiuk commented Sep 27, 2026

Copy link
Copy Markdown
Member

Several example Dags built their shell command text from values that are only known at run time — another task's output, or a Dag param rendered through Jinja. Users copy example Dags into real deployments, so the pattern they show is the pattern that ships. These examples now keep the command text constant and pass the value to the command through env, so the shell never parses it as part of the command.

Changed examples:

  • example_dag_decorator — the IP address fetched by get_ip reaches echo_ip_info through EXTERNAL_IP.
  • example_bash_operator / example_bash_decorator — show_dag_folder_stats reads describe_dag_folder's XComs through env.
  • edge3 integration_test — classic_bash reads params.mapping_count through env.

A new check-example-dag-shell-commands prek hook keeps it that way. On files under example_dags/ it flags a bash_command (or a @task.bash return value) built with an f-string, str.format, % or + from a runtime value, and a Jinja expression that renders xcom_pull, params or dag_run.conf into command text. Literals, module-level constants and context values such as {{ ds }} are fine. The hook has unit tests under scripts/tests/ci/prek/.

🤖 Generated with Claude Code

potiuk added 2 commits October 5, 2026 01:17
Several example Dags built their shell command text out of values that
are only known at run time: another task's output, or a Dag param
rendered through Jinja. Users copy example Dags into real deployments,
so the pattern they show is the pattern that ships. Keep the command
text constant and hand the value to the command through ``env``
instead, so the shell never parses it as part of the command.

Add a ``check-example-dag-shell-commands`` prek hook that flags a
``bash_command`` (or a ``@task.bash`` return value) built with an
f-string, ``str.format``, ``%`` or ``+`` from a runtime value, or with a
Jinja expression rendering ``xcom_pull``, ``params`` or ``dag_run.conf``
into the command text.

Generated-by: Claude Opus 5
The decorator example hands the describe_dag_folder XComs straight to env,
and a value that json.loads turned into an int makes the subprocess fail
before the command runs. The BashOperator example is unaffected because its
Jinja templates always render to strings.

Generated-by: Claude Opus 5
@potiuk
potiuk force-pushed the example-dag-env-passing branch from 9a04292 to 466f853 Compare October 4, 2026 23:27
@potiuk
potiuk requested a review from ephraimbuddy October 13, 2026 14:27
@potiuk potiuk added the backport-to-v3-4-test Backport to v3-4-test label Oct 16, 2026
@potiuk potiuk added this to the Airflow 3.4.0 milestone Oct 16, 2026
@potiuk

potiuk commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

@ephraimbuddy Could you take a look at this when you have a moment? It's targeted at 3.4.0 and needs a review to make the cut on 2026-10-19. CI is green.

@vatsrahul1001 vatsrahul1001 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. The examples keep the command text constant and pass runtime values through env, and the new hook has tests for the accepted and rejected shapes. Two small comments inline.

Comment thread .pre-commit-config.yaml Resolved
Python 3.10 support is gone and the other prek scripts pin 3.11, so the 3.10 pin made prek provision an extra interpreter just for this hook. The prose also follows the project's "Dag" spelling.

Generated-by: Claude Opus 5
@potiuk
potiuk merged commit 486f836 into apache:main Oct 19, 2026
3 checks passed
@potiuk
potiuk deleted the example-dag-env-passing branch October 19, 2026 15:31
@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

potiuk added a commit that referenced this pull request Oct 19, 2026
… env (#73787)

* Pass runtime values to example Dag shell commands through env

Several example Dags built their shell command text out of values that
are only known at run time: another task's output, or a Dag param
rendered through Jinja. Users copy example Dags into real deployments,
so the pattern they show is the pattern that ships. Keep the command
text constant and hand the value to the command through ``env``
instead, so the shell never parses it as part of the command.

Add a ``check-example-dag-shell-commands`` prek hook that flags a
``bash_command`` (or a ``@task.bash`` return value) built with an
f-string, ``str.format``, ``%`` or ``+`` from a runtime value, or with a
Jinja expression rendering ``xcom_pull``, ``params`` or ``dag_run.conf``
into the command text.

Generated-by: Claude Opus 5

* Pass file_count to the bash decorator example as a string

The decorator example hands the describe_dag_folder XComs straight to env,
and a value that json.loads turned into an int makes the subprocess fail
before the command runs. The BashOperator example is unaffected because its
Jinja templates always render to strings.

Generated-by: Claude Opus 5

* Align the example Dag shell-command hook with the other prek scripts

Python 3.10 support is gone and the other prek scripts pin 3.11, so the 3.10 pin made prek provision an extra interpreter just for this hook. The prose also follows the project's "Dag" spelling.
(cherry picked from commit 486f836)

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Generated-by: Claude Opus 5
potiuk added a commit that referenced this pull request Oct 19, 2026
… env (#73787) (#75121)

* Pass runtime values to example Dag shell commands through env

Several example Dags built their shell command text out of values that
are only known at run time: another task's output, or a Dag param
rendered through Jinja. Users copy example Dags into real deployments,
so the pattern they show is the pattern that ships. Keep the command
text constant and hand the value to the command through ``env``
instead, so the shell never parses it as part of the command.

Add a ``check-example-dag-shell-commands`` prek hook that flags a
``bash_command`` (or a ``@task.bash`` return value) built with an
f-string, ``str.format``, ``%`` or ``+`` from a runtime value, or with a
Jinja expression rendering ``xcom_pull``, ``params`` or ``dag_run.conf``
into the command text.

Generated-by: Claude Opus 5

* Pass file_count to the bash decorator example as a string

The decorator example hands the describe_dag_folder XComs straight to env,
and a value that json.loads turned into an int makes the subprocess fail
before the command runs. The BashOperator example is unaffected because its
Jinja templates always render to strings.

Generated-by: Claude Opus 5

* Align the example Dag shell-command hook with the other prek scripts

Python 3.10 support is gone and the other prek scripts pin 3.11, so the 3.10 pin made prek provision an extra interpreter just for this hook. The prose also follows the project's "Dag" spelling.
(cherry picked from commit 486f836)


Generated-by: Claude Opus 5

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
vatsrahul1001 pushed a commit that referenced this pull request Oct 20, 2026
… env (#73787) (#75121)

* Pass runtime values to example Dag shell commands through env

Several example Dags built their shell command text out of values that
are only known at run time: another task's output, or a Dag param
rendered through Jinja. Users copy example Dags into real deployments,
so the pattern they show is the pattern that ships. Keep the command
text constant and hand the value to the command through ``env``
instead, so the shell never parses it as part of the command.

Add a ``check-example-dag-shell-commands`` prek hook that flags a
``bash_command`` (or a ``@task.bash`` return value) built with an
f-string, ``str.format``, ``%`` or ``+`` from a runtime value, or with a
Jinja expression rendering ``xcom_pull``, ``params`` or ``dag_run.conf``
into the command text.

Generated-by: Claude Opus 5

* Pass file_count to the bash decorator example as a string

The decorator example hands the describe_dag_folder XComs straight to env,
and a value that json.loads turned into an int makes the subprocess fail
before the command runs. The BashOperator example is unaffected because its
Jinja templates always render to strings.

Generated-by: Claude Opus 5

* Align the example Dag shell-command hook with the other prek scripts

Python 3.10 support is gone and the other prek scripts pin 3.11, so the 3.10 pin made prek provision an extra interpreter just for this hook. The prose also follows the project's "Dag" spelling.
(cherry picked from commit 486f836)


Generated-by: Claude Opus 5

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants