From 383144353e061d9f19ae41b443bb8c9e20cb4eb4 Mon Sep 17 00:00:00 2001 From: fritz-astronomer <80706212+fritz-astronomer@users.noreply.github.com> Date: Wed, 29 Jun 2022 10:35:25 -0400 Subject: [PATCH 1/5] Update templates-ref.rst --- docs/apache-airflow/templates-ref.rst | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/apache-airflow/templates-ref.rst b/docs/apache-airflow/templates-ref.rst index f3c4a46978a33..f5e99fa0749e2 100644 --- a/docs/apache-airflow/templates-ref.rst +++ b/docs/apache-airflow/templates-ref.rst @@ -115,6 +115,8 @@ dot notation. Here are some examples of what is possible: Refer to the models documentation for more information on the objects' attributes and methods. +Airflow Variables in Templates +--------- The ``var`` template variable allows you to access variables defined in Airflow's UI. You can access them as either plain-text or JSON. If you use JSON, you are also able to walk nested structures, such as dictionaries like: @@ -125,11 +127,17 @@ It is also possible to fetch a variable by string if needed with ``{{ var.json.get('my.dict.var', {'key1': 'val1'}) }}``. Defaults can be supplied in case the variable does not exist. -Similarly, Airflow Connections data can be accessed via the ``conn`` template variable. -For example, you could use expressions in your templates like ``{{ conn.my_conn_id.login }}``, + +Airflow Connections in Templates +--------- +Similarly, Airflow Connections data can be accessed via the ``conn`` template variable. For example, you could use expressions in your templates like ``{{ conn.my_conn_id.login }}``, ``{{ conn.my_conn_id.password }}``, etc. + Just like with ``var`` it's possible to fetch a connection by string (e.g. ``{{ conn.get('my_conn_id_'+index).host }}`` -) or provide defaults (e.g ``{{ conn.get('my_conn_id', {"host": "host1", "login": "user1"}).host }}``) +) or provide defaults (e.g ``{{ conn.get('my_conn_id', {"host": "host1", "login": "user1"}).host }}``). + +Additionally, the `extras` field of a connection can be fetched as a Python Dictionary by the ``extra_dejson`` field, e.g. +``conn.my_aws_conn_id.extra_dejson.region_name`` would fetch ``region_name`` out of ``extras``. Filters ------- From 6f31ac614e2f009311eb6b7a15ae8c524cd64160 Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Wed, 29 Jun 2022 15:42:09 +0100 Subject: [PATCH 2/5] Apply suggestions from code review --- docs/apache-airflow/templates-ref.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/apache-airflow/templates-ref.rst b/docs/apache-airflow/templates-ref.rst index f5e99fa0749e2..92425457ae2b2 100644 --- a/docs/apache-airflow/templates-ref.rst +++ b/docs/apache-airflow/templates-ref.rst @@ -116,7 +116,7 @@ Refer to the models documentation for more information on the objects' attributes and methods. Airflow Variables in Templates ---------- +------------------------------ The ``var`` template variable allows you to access variables defined in Airflow's UI. You can access them as either plain-text or JSON. If you use JSON, you are also able to walk nested structures, such as dictionaries like: @@ -129,7 +129,7 @@ supplied in case the variable does not exist. Airflow Connections in Templates ---------- +--------------------------------- Similarly, Airflow Connections data can be accessed via the ``conn`` template variable. For example, you could use expressions in your templates like ``{{ conn.my_conn_id.login }}``, ``{{ conn.my_conn_id.password }}``, etc. From b95d37afa792e66129edbb3444a1cb72afff758f Mon Sep 17 00:00:00 2001 From: fritz-astronomer <80706212+fritz-astronomer@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:54:33 -0400 Subject: [PATCH 3/5] Update docs/apache-airflow/templates-ref.rst Co-authored-by: Jed Cunningham <66968678+jedcunningham@users.noreply.github.com> --- docs/apache-airflow/templates-ref.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/apache-airflow/templates-ref.rst b/docs/apache-airflow/templates-ref.rst index 92425457ae2b2..2103bfc731110 100644 --- a/docs/apache-airflow/templates-ref.rst +++ b/docs/apache-airflow/templates-ref.rst @@ -136,7 +136,7 @@ Similarly, Airflow Connections data can be accessed via the ``conn`` template va Just like with ``var`` it's possible to fetch a connection by string (e.g. ``{{ conn.get('my_conn_id_'+index).host }}`` ) or provide defaults (e.g ``{{ conn.get('my_conn_id', {"host": "host1", "login": "user1"}).host }}``). -Additionally, the `extras` field of a connection can be fetched as a Python Dictionary by the ``extra_dejson`` field, e.g. +Additionally, the ``extras`` field of a connection can be fetched as a Python Dictionary with the ``extra_dejson`` field, e.g. ``conn.my_aws_conn_id.extra_dejson.region_name`` would fetch ``region_name`` out of ``extras``. Filters From e3e79708e40f09be12d3cfc1ca1aebe72e4a75cd Mon Sep 17 00:00:00 2001 From: fritz-astronomer <80706212+fritz-astronomer@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:54:47 -0400 Subject: [PATCH 4/5] Update docs/apache-airflow/templates-ref.rst Co-authored-by: Jed Cunningham <66968678+jedcunningham@users.noreply.github.com> --- docs/apache-airflow/templates-ref.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/apache-airflow/templates-ref.rst b/docs/apache-airflow/templates-ref.rst index 2103bfc731110..d7bb2ce1ea9ed 100644 --- a/docs/apache-airflow/templates-ref.rst +++ b/docs/apache-airflow/templates-ref.rst @@ -117,8 +117,8 @@ attributes and methods. Airflow Variables in Templates ------------------------------ -The ``var`` template variable allows you to access variables defined in Airflow's -UI. You can access them as either plain-text or JSON. If you use JSON, you are +The ``var`` template variable allows you to access Airflow Variables. +You can access them as either plain-text or JSON. If you use JSON, you are also able to walk nested structures, such as dictionaries like: ``{{ var.json.my_dict_var.key1 }}``. From 870e85b7933da9670333045cfe23d009e926e911 Mon Sep 17 00:00:00 2001 From: Jed Cunningham <66968678+jedcunningham@users.noreply.github.com> Date: Thu, 30 Jun 2022 12:34:01 -0600 Subject: [PATCH 5/5] Update docs/apache-airflow/templates-ref.rst --- docs/apache-airflow/templates-ref.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/apache-airflow/templates-ref.rst b/docs/apache-airflow/templates-ref.rst index d7bb2ce1ea9ed..2f78ebcce3fc0 100644 --- a/docs/apache-airflow/templates-ref.rst +++ b/docs/apache-airflow/templates-ref.rst @@ -136,7 +136,7 @@ Similarly, Airflow Connections data can be accessed via the ``conn`` template va Just like with ``var`` it's possible to fetch a connection by string (e.g. ``{{ conn.get('my_conn_id_'+index).host }}`` ) or provide defaults (e.g ``{{ conn.get('my_conn_id', {"host": "host1", "login": "user1"}).host }}``). -Additionally, the ``extras`` field of a connection can be fetched as a Python Dictionary with the ``extra_dejson`` field, e.g. +Additionally, the ``extras`` field of a connection can be fetched as a Python Dictionary with the ``extra_dejson`` field, e.g. ``conn.my_aws_conn_id.extra_dejson.region_name`` would fetch ``region_name`` out of ``extras``. Filters