-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create UndefinedJinjaVariablesRule to ease upgrade to 2.0 #11144
Comments
Hi, I am new to both Airflow and contributing to FOSS. I had one quick query - Thanks! Looking forward to contribute and learn more! |
Yep. |
I had a few doubts asking them here - Currently I was writing the following logic for
Below is the script version
Does this logic look like something we could follow? I did have a look at |
@ashmeet13 That check looks like a good start yes, but not quite there. I don't think your |
Also check our BaseOperator.render_template for all the possible locations/field types we render templates on. You'll need to replicate much of that logic to handle all the types (inside lists, dicts, etc. etc.) |
Got it - thank you so much. Will update on the progress or in case of any further doubts! |
Some progress that I have made. Thanks @ashb for guiding towards With this I was able to improve the logic to extract undefined variables in a template to this -
Take into the consideration the following DAG -
The above check would print/return this -
One blocker still that I have is how exactly will I be able to get the dags when the user runs Edited: Adding the Stack Overflow source I used |
Part of Issue apache#8765 - adding a rule to check for undefined jinja variables when upgrading to Airflow2.0 Logic - Use a DagBag to pull all dags and iterate over every dag. For every dag the task will be rendered using an updated Jinja Environment using - jinja2.DebugUndefined This will render the template leaving undefined variables as they were. Using regex we can extract the variables and present possible error cases when upgrading.
Adding a rule to check for undefined jinja variables when upgrading to Airflow2.0 Logic - Use a DagBag to pull all dags and iterate over every dag. For every dag the task will be rendered using an updated Jinja Environment using - jinja2.DebugUndefined This will render the template leaving undefined variables as they were. Using regex we can extract the variables and present possible error cases when upgrading.
Adding a rule to check for undefined jinja variables when upgrading to Airflow2.0 Logic - Use a DagBag to pull all dags and iterate over every dag. For every dag the task will be rendered using an updated Jinja Environment using - jinja2.DebugUndefined This will render the template leaving undefined variables as they were. Using regex we can extract the variables and present possible error cases when upgrading.
Adding a rule to check for undefined jinja variables when upgrading to Airflow2.0
Closed via #11241 |
) Adding a rule to check for undefined jinja variables when upgrading to Airflow2.0 (cherry picked from commit 18100a0)
This issue is part of #8765
Rule
Create
UndefinedJinjaVariablesRule
which corresponds toentry in UPDATING.md. Introduced in #11016
This rule should check if any of the jinja templates use undefined variables. This might not be always possible, as this might involve the dynamic generation of some context variables, but likely we can at least print some warning or "double-check this" statements.
How to guide
To implement a new rule, create a class that inherits from
airflow.upgrade.rules.base_rule.BaseRule
.It will be auto-registered and used by
airflow upgrade-check
command. The custom rule class has to havetitle
,description
properties and should implementcheck
method which returns a list of error messages in case ofincompatibility.
For example:
airflow/airflow/upgrade/rules/conn_type_is_not_nullable.py
Lines 25 to 42 in ea36166
Remember to open the PR against
v1-10-test
branch.The text was updated successfully, but these errors were encountered: