You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by je...@apache.org on 2022/02/08 00:16:25 UTC

[airflow] 04/07: Update example DAGs (#21372)

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

jedcunningham pushed a commit to branch v2-2-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 99abbfc873d3df070fff5926d69c31bfad462359
Author: Jed Cunningham <66...@users.noreply.github.com>
AuthorDate: Mon Feb 7 11:24:31 2022 -0700

    Update example DAGs (#21372)
    
    (cherry picked from commit 7a38ec2ad3b3bd6fda5e1ee9fe9e644ccb8b4c12)
---
 .../example_dags/example_passing_params_via_test_command.py   | 11 ++++++-----
 airflow/example_dags/tutorial.py                              |  2 --
 docs/apache-airflow/tutorial.rst                              |  9 ++-------
 tests/cli/commands/test_task_command.py                       |  1 -
 4 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/airflow/example_dags/example_passing_params_via_test_command.py b/airflow/example_dags/example_passing_params_via_test_command.py
index e3f04c4..d4781af 100644
--- a/airflow/example_dags/example_passing_params_via_test_command.py
+++ b/airflow/example_dags/example_passing_params_via_test_command.py
@@ -68,17 +68,18 @@ with DAG(
 ) as dag:
     run_this = my_py_command(params={"miff": "agg"})
 
-    my_templated_command = dedent(
+    my_command = dedent(
+        """
+        echo "'foo' was passed in via Airflow CLI Test command with value '$FOO'"
+        echo "'miff' was passed in via BashOperator with value '$MIFF'"
         """
-        echo " 'foo was passed in via Airflow CLI Test command with value {{ params.foo }} "
-        echo " 'miff was passed in via BashOperator with value {{ params.miff }} "
-    """
     )
 
     also_run_this = BashOperator(
         task_id='also_run_this',
-        bash_command=my_templated_command,
+        bash_command=my_command,
         params={"miff": "agg"},
+        env={"FOO": "{{ params.foo }}", "MIFF": "{{ params.miff }}"},
     )
 
     env_var_test_task = print_env_vars()
diff --git a/airflow/example_dags/tutorial.py b/airflow/example_dags/tutorial.py
index 1049772..ff2bd2f 100644
--- a/airflow/example_dags/tutorial.py
+++ b/airflow/example_dags/tutorial.py
@@ -109,7 +109,6 @@ with DAG(
     {% for i in range(5) %}
         echo "{{ ds }}"
         echo "{{ macros.ds_add(ds, 7)}}"
-        echo "{{ params.my_param }}"
     {% endfor %}
     """
     )
@@ -118,7 +117,6 @@ with DAG(
         task_id='templated',
         depends_on_past=False,
         bash_command=templated_command,
-        params={'my_param': 'Parameter I passed in'},
     )
     # [END jinja_template]
 
diff --git a/docs/apache-airflow/tutorial.rst b/docs/apache-airflow/tutorial.rst
index 1c32e78..0034b2c 100644
--- a/docs/apache-airflow/tutorial.rst
+++ b/docs/apache-airflow/tutorial.rst
@@ -151,13 +151,8 @@ stamp").
     :end-before: [END jinja_template]
 
 Notice that the ``templated_command`` contains code logic in ``{% %}`` blocks,
-references parameters like ``{{ ds }}``, calls a function as in
-``{{ macros.ds_add(ds, 7)}}``, and references a user-defined parameter
-in ``{{ params.my_param }}``.
-
-The ``params`` hook in ``BaseOperator`` allows you to pass a dictionary of
-parameters and/or objects to your templates. Please take the time
-to understand how the parameter ``my_param`` makes it through to the template.
+references parameters like ``{{ ds }}``, and calls a function as in
+``{{ macros.ds_add(ds, 7)}}``.
 
 Files can also be passed to the ``bash_command`` argument, like
 ``bash_command='templated_command.sh'``, where the file location is relative to
diff --git a/tests/cli/commands/test_task_command.py b/tests/cli/commands/test_task_command.py
index 201af16..76c6cdb 100644
--- a/tests/cli/commands/test_task_command.py
+++ b/tests/cli/commands/test_task_command.py
@@ -263,7 +263,6 @@ class TestCliTasks(unittest.TestCase):
 
         assert 'echo "2016-01-01"' in output
         assert 'echo "2016-01-08"' in output
-        assert 'echo "Parameter I passed in"' in output
 
     def test_cli_run_when_pickle_and_dag_cli_method_selected(self):
         """