From 3fa6d25362b0a61dec389de1a27068bf0ce413ae Mon Sep 17 00:00:00 2001 From: fritz-astronomer <80706212+fritz-astronomer@users.noreply.github.com> Date: Thu, 30 Jun 2022 18:33:07 -0400 Subject: [PATCH] Update templates doc to mention `extras` and format Airflow Vars / Conns (#24735) (cherry picked from commit 54d5972cb87b7b0605d34a655cfe87b661fd75f1) --- docs/apache-airflow/templates-ref.rst | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/apache-airflow/templates-ref.rst b/docs/apache-airflow/templates-ref.rst index f3c4a46978a33..2f78ebcce3fc0 100644 --- a/docs/apache-airflow/templates-ref.rst +++ b/docs/apache-airflow/templates-ref.rst @@ -115,8 +115,10 @@ dot notation. Here are some examples of what is possible: Refer to the models documentation for more information on the objects' attributes and methods. -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 +Airflow Variables in Templates +------------------------------ +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 }}``. @@ -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 with the ``extra_dejson`` field, e.g. +``conn.my_aws_conn_id.extra_dejson.region_name`` would fetch ``region_name`` out of ``extras``. Filters -------