Fix template_ext processing for Kubernetes Pod Operator
See original GitHub issueThe “template_ext” mechanism is useful for automatically loading and jinja-processing files which are specified in parameters of Operators. However this might lead to certain problems for example (from slack conversation):
The templated_fields in KubernetesPodOperator seems cause the error airflow jinja2.exceptions.TemplateNotFound when some character in the column, e.g / in env_vars.
The code got error.
env_vars=[
k8s.V1EnvVar(
name="GOOGLE_APPLICATION_CREDENTIALS",
value="/var/secrets/google/service-account.json",
),
I believe the behaviour changed comparing to not-so-long-past. Some of the changes with processing parameters with jinja recursively caused this template behaviour to be applied also nested parameters like above.
There were also several discussions and user confusion with this behaviour: #15942, #16922
There are two ways we could improve the situation:
-
limit the “template_extension” resolution to only direct string kwargs passed to the operator (I think this is no brainer and we should do it)
-
propose some “escaping” mechanism, where you could either disable template_extension processing entirely or somehow mark the parameters that should not be treated as templates.
Here I have several proposals:
a) we could add “skip_template_ext_processing” or similar parameter in BaseOperator <- I do not like it as many operators rely on this behaviour for a good reason b) we could add “template_ext” parameter in the operator that could override the original class-level-field <- I like this one a lot c) we could add “disable_template_ext_pattern” (str) parameter where we could specify list of regexp’s where we could filter out only specific values <- this one will allow to disable template_ext much more “selectively” - only for certain parameters.
UPDATE: It only affects Kubenernetes Pod Operator due to it’s recursive behaviour and should be fixed there.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (9 by maintainers)
Top GitHub Comments
Oh, of course we shouldn’t use
typing.Literal
. I was just borrowing the name and should’ve clarified. We should implement something likefrom airflow import Literal
.For people confused by the release 2.0.2
the commit
Fix using XCom with ''KubernetesPodOperator'' (#17760)
mostly fix the error of the templating of the K8S secretsso don’t use 2.0.1 !