This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 900e5e222f8 Make example_xcom resistant to escaping issues. (#63200)
900e5e222f8 is described below

commit 900e5e222f8ed842918134572fd6a1c3c176cf0b
Author: Jarek Potiuk <[email protected]>
AuthorDate: Tue Mar 10 14:43:46 2026 +0100

    Make example_xcom resistant to escaping issues. (#63200)
---
 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 e17ad56d8ca..304e7fa0c65 100644
--- a/airflow-core/src/airflow/example_dags/example_xcom.py
+++ b/airflow-core/src/airflow/example_dags/example_xcom.py
@@ -77,12 +77,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,
     )
 

Reply via email to