ecerulm opened a new pull request, #29016:
URL: https://github.com/apache/airflow/pull/29016
Currently the KubernetesPodOperator `env_vars` will be printed on the task
logs if there is any templating error (like an `UndefinedError`,
`TemplateSyntaxError` or `KeyError`)
```
[2023-01-16, 23:03:17 UTC] {abstractoperator.py:592} ERROR - Exception
rendering Jinja template for task 'dry_run_demo', field 'env_vars'. Template:
[{'name': 'password', 'value': 'secretpassword', 'value_from': None}, {'name':
'VAR2', 'value': '{{ var.value.nonexisting}}', 'value_from': None}]
Traceback (most recent call last):
File
"/Users/rubelagu/.pyenv/versions/3.10.7/envs/venv-airflow-250/lib/python3.10/site-packages/airflow/models/abstractoperator.py",
line 585, in _do_render_template_fields
rendered_content = self.render_template(
File
"/Users/rubelagu/.pyenv/versions/3.10.7/envs/venv-airflow-250/lib/python3.10/site-packages/airflow/models/abstractoperator.py",
line 657, in render_template
return [self.render_template(element, context, jinja_env, oids) for
element in value]
File
"/Users/rubelagu/.pyenv/versions/3.10.7/envs/venv-airflow-250/lib/python3.10/site-packages/airflow/models/abstractoperator.py",
line 657, in <listcomp>
return [self.render_template(element, context, jinja_env, oids) for
element in value]
File
"/Users/rubelagu/.pyenv/versions/3.10.7/envs/venv-airflow-250/lib/python3.10/site-packages/airflow/models/abstractoperator.py",
line 664, in render_template
self._render_nested_template_fields(value, context, jinja_env, oids)
File
"/Users/rubelagu/.pyenv/versions/3.10.7/envs/venv-airflow-250/lib/python3.10/site-packages/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py",
line 321, in _render_nested_template_fields
self._do_render_template_fields(content, ("value", "name"), context,
jinja_env, seen_oids)
...
...
File
"/Users/rubelagu/.pyenv/versions/3.10.7/envs/venv-airflow-250/lib/python3.10/site-packages/airflow/models/variable.py",
line 141, in get
raise KeyError(f"Variable {key} does not exist")
KeyError: 'Variable nonexisting does not exist'
```
this happens when there is any error on the templates. For example a
`KeyError` raised when using `var.value.somemistypedvalue`:
```
env_vars={
"password": "{{ conn.test_connection.password }}",
"VAR2": "{{ var.value.nonexisting}}",
},
```
This PR uses the `airflow.utils.log.secrets_maker.redact` to remove any
field contained in `DEFAULT_SENSITIVE_FIELDS` or
`sensitive_var_conn_names`.
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
---
**^ Add meaningful description above**
Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)**
for more information.
In case of fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party
License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a
newsfragment file, named `{pr_number}.significant.rst` or
`{issue_number}.significant.rst`, in
[newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]