'Airflow how to read JSON Input Params which includes '-' in the middle of param using Jinja
I’m running my DAG with configuration JSON, which includes parameters which includes -, e.g. market-name
When I’m trying to read it using the following Jinja template:
path_prefix = f"market={{{{ params.market-name }}}}/configuration"
I’m getting the following error:
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'market'
It seems to me that Jinja doesn’t identify the full param name market-name but get the first part before the - which is market .
My questions:
- Does Jinja supports having
-in the middle of a param (e.g.market-name) or should I avoid it from the beginning and usemarket_nameinstead? - If Jinja doesn’t support having a
-in the middle of a param
- Should I escape the
market-name? - How should I escape it?
- Should I use
{{ params.market-name }}instead of{{{{ params.market-name }}}}?
Solution 1:[1]
This is not Airflow bug. I reported it in this issue and this is a problem coming from Jinja/Python.
I could have not find any official documentation in Jinja that explains it but several reports mention that Jinja uses python interpreter's identifiers (see this answer and this answer). It might be best to report this issue to Jinja add documentation about it.
You can just avoid using -.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
