BobDu commented on code in PR #27316:
URL: https://github.com/apache/airflow/pull/27316#discussion_r1006950778


##########
docs/apache-airflow/best-practices.rst:
##########
@@ -213,6 +213,30 @@ or if you need to deserialize a json object from the 
variable :
 
     {{ var.json.<variable_name> }}
 
+Ensure use variable with template in operator, not get it in top level code.
+
+Bad example:
+
+.. code-block:: python
+
+    from airflow.models import Variable
+
+    foo_var = Variable.get("foo")
+    bash_use_variable_bad = BashOperator(
+        task_id="bash_use_variable_bad", bash_command="echo variable 
foo=${foo_env}", env={"foo_env": foo_var}
+    )
+
+Good example:
+
+.. code-block:: python
+
+    bash_use_variable_good = BashOperator(
+        task_id="bash_use_variable_good",
+        bash_command="echo variable foo=${foo_env}",
+        env={"foo_env": "{{ var.value.get('foo') }}"},
+    )
+
+

Review Comment:
   ? `bash_command="echo variable foo=${Variable.get('foo')}"` is not a 
effective syntax.
   Are you want to say `bash_command=f"echo variable 
foo={Variable.get('foo')}"` ?
   



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to