-
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
Merged
amoghrajesh
merged 6 commits into
apache:main
from
astronomer:integrate-user-defined-macros
May 19, 2025
Merged
Support macros defined via plugins in Airflow 3 #50642
amoghrajesh
merged 6 commits into
apache:main
from
astronomer:integrate-user-defined-macros
May 19, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ashb
reviewed
May 15, 2025
kaxil
reviewed
May 15, 2025
Contributor
Author
|
Working on the test failures |
amoghrajesh
commented
May 16, 2025
Contributor
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
Contributor
Author
|
Thanks @zach-overflow! I will revert that off once I land this one |
ashb
reviewed
May 19, 2025
ashb
approved these changes
May 19, 2025
amoghrajesh
added a commit
that referenced
this pull request
May 20, 2025
(cherry picked from commit f008411) Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
potiuk
pushed a commit
that referenced
this pull request
May 21, 2025
dadonnelly316
pushed a commit
to dadonnelly316/airflow
that referenced
this pull request
May 26, 2025
kaxil
pushed a commit
that referenced
this pull request
Jun 3, 2025
sanederchik
pushed a commit
to sanederchik/airflow
that referenced
this pull request
Jun 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.