-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Support macros defined via plugins in Airflow 3 #50642
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
Support macros defined via plugins in Airflow 3 #50642
Conversation
|
Working on the test failures |
zach-overflow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @amoghrajesh, I'm excited to see this! One small suggestion: It probably would make sense to remove the doc warning I added in https://github.com/apache/airflow/pull/50357/files
|
Thanks @zach-overflow! I will revert that off once I land this one |
(cherry picked from commit f008411) Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
closes: #48476
What the issue is?
Airflow is supposed to support macros -- both present internally like:
uuid,datetime.now,ds_addetc in conjunction with the user defined macros that are registered via plugins.Check references here: https://airflow.apache.org/docs/apache-airflow/stable/templates-ref.html and a usage example here: https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/plugins.html#example.
Why is it important?
Airflow 2 supported this feature and wouldve built tons of dags around it which would break for those users during if not this is not supported in airflow 3 and would serve as a blocker for those users.
Some examples of callouts: https://apache-airflow.slack.com/archives/CCZRF2U5A/p1746707742015169 which we referred to this issue: #48476.
Approach
Using the older approach itself where we have a utility:
integrate_macros_pluginspresent that registers the user defined and global macros with airflow core by making the module by users under:airflow.sdk.definitionsand it can be accessed usingMacrosAccessorin the context:airflow/task-sdk/src/airflow/sdk/execution_time/task_runner.py
Line 175 in 08cc57d
integrate_macros_pluginshas been updated to refer to themacrosmodule inairflow.sdk.definitionsinstead of the older one:airflow.macrosTesting
Steps
1. Creating few macros:
emojiify_macrothat takes some text and converts it into an emoji and returnssupport_ticket_macroreturns a support ticket link based on dag id and task id2. Define these in an airflow plugin:
3. Ensure that the plugin has been loaded:
4. Now check if the macros are loaded in that plugin:
Run
airflow pluginin CLI:5. Define dags that can check the plugins out
DAG:
Result:

Logs:
TODO:
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.