Render template for dictionary keys
- Dominant language
- Python
- Stars
- 46.9k
- Forks
- 17.8k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 483
Description
When rendering jinja template, it is rendered recursively for some kind of collection type. (list, tuple, set, ...)
However, for the dictionary type, only the `value` part is rendered while the `key` part is not rendered.
I am wondering if this behavior is intended due to some unwanted behavior.
If not, I want to suggest to render the keys as well during the rendering.
**Use case / motivation**
In my use case, both keys and values have to dynamically change.
When rendering the following dictionary object, (with `template_key = "some_key"` and `template_value = "some_value"`)
```
{'{{ template_key }}': '{{ template_value }}'}
```
Currently, the behavior is
```
{'{{ template_key }}': 'some_value'}
```
However, I would like to have
```
{'some_key': 'some_value'}
```
**Are you willing to submit a PR?**
Yes, I would like to contribute!
I believe the following line has to be modified.
https://github.com/apache/airflow/blob/2b10680a2f5188400459089713876c1ce49f1caf/airflow/models/baseoperator.py#L1068
**Related Issues**
I am not aware of other related issue.
Contributor guide
Research direction
Read airflow/models/baseoperator.py around line 1068 and inspect how recursive template rendering handles dictionaries. Reproduce the issue with the provided dictionary example, then verify that both the key and value resolve to their expected strings when the work is complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100