ashmeet13 commented on issue #11144:
URL: https://github.com/apache/airflow/issues/11144#issuecomment-700128375
I had a few doubts asking them here -
Currently I was writing the following logic for `check` -
For a given dag -
1. It will gather all the tasks - `dag.tasks`
2. Iterate over the task list and for every task
- Get Jinja2 environment from `task.get_template_env()`
- Find Jinja2 variables for all `task.template_fields`
- Verify that all the above gathered variables are present in
`task.params`
3. Return a list of messages for every missing variable in `task.params`
Below is the script version
```
for task in dag.tasks:
env = task.get_template_env()
params = set(task.params.keys())
for attr_name in task.template_fields:
content = getattr(task, attr_name)
parsed = env.parse(content)
template_varaibles =
meta.find_undeclared_variables(parsed) # Returns a set of variables present in
the template
undefined_variables = template_varaibles-params # Set
difference
```
Does this logic look like something we could follow?
And if yes then how can I write this logic to check for every DAG?
I did have a look at `DagBag` but I do not know how should I write a test
for it.
Sorry for the newbie questions - would be really helpful if you could guide
on these points.
----------------------------------------------------------------
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]