dhuang commented on a change in pull request #6793: [AIRFLOW-1076] Add get
method for template variable accessor
URL: https://github.com/apache/airflow/pull/6793#discussion_r357293479
##########
File path: docs/macros-ref.rst
##########
@@ -88,7 +88,12 @@ 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
also able to walk nested structures, such as dictionaries like:
-``{{ var.json.my_dict_var.key1 }}``
+``{{ var.json.my_dict_var.key1 }}``.
+
+It is also possible to fetch a variable by string if needed with
+``{{ var.value.get('my.var', 'fallback') }}`` or
Review comment:
This resolves my original reason for adding this method (periods in variable
keys), but that default logic doesn't work because it throws a KeyError first
when it's missing. `Error rendering template: 'Variable my.var does not exist'`
is the error I get from your example.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services