This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v3-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-1-test by this push:
new d7ecffacad6 [v3-1-test] Make example_xcom resistant to escaping
issues. (#63200) (#63268)
d7ecffacad6 is described below
commit d7ecffacad6a690add8985c9eede2b356c7e1d57
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Mar 10 22:03:29 2026 +0100
[v3-1-test] Make example_xcom resistant to escaping issues. (#63200)
(#63268)
(cherry picked from commit 900e5e222f8ed842918134572fd6a1c3c176cf0b)
Co-authored-by: Jarek Potiuk <[email protected]>
---
airflow-core/src/airflow/example_dags/example_xcom.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/airflow-core/src/airflow/example_dags/example_xcom.py
b/airflow-core/src/airflow/example_dags/example_xcom.py
index 8b8bc5bebd7..88435379642 100644
--- a/airflow-core/src/airflow/example_dags/example_xcom.py
+++ b/airflow-core/src/airflow/example_dags/example_xcom.py
@@ -78,12 +78,22 @@ with DAG(
'echo "value_by_return"',
)
+ # This example shows a safe way of passing XCom values to a BashOperator
via environment variables.
+ # The values are templated into the bash_command and then set as
environment variables for the
+ # command to use. This is a recommended pattern for passing XCom values to
BashOperator, as it avoids
+ # issues with quoting and escaping that can arise when trying to directly
template XCom values
+ # into.
bash_pull = BashOperator(
task_id="bash_pull",
bash_command='echo "bash pull demo" && '
- f'echo "The xcom pushed manually is {XComArg(bash_push,
key="manually_pushed_value")}" && '
- f'echo "The returned_value xcom is {XComArg(bash_push)}" && '
+ "echo \"The xcom pushed manually is '$MANUALLY_PUSHED_VALUE'\" && "
+ "echo \"The returned_value xcom is '$RETURNED_VALUE'\" && "
'echo "finished"',
+ env={
+ "MANUALLY_PUSHED_VALUE": str(XComArg(bash_push,
key="manually_pushed_value")),
+ "RETURNED_VALUE": str(XComArg(bash_push)),
+ },
+ append_env=True,
do_xcom_push=False,
)