Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airflow-core/src/airflow/macros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
from __future__ import annotations

from airflow.sdk.definitions.macros import ( # noqa: F401
from airflow.sdk.execution_time.macros import ( # noqa: F401
datetime,
datetime_diff_for_humans,
dateutil,
Expand Down
4 changes: 2 additions & 2 deletions airflow-core/src/airflow/plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def integrate_macros_plugins() -> None:
global plugins
global macros_modules

from airflow.sdk.definitions import macros
from airflow.sdk.execution_time import macros

if macros_modules is not None:
return
Expand All @@ -525,7 +525,7 @@ def integrate_macros_plugins() -> None:
if plugin.name is None:
raise AirflowPluginException("Invalid plugin name")

macros_module = make_module(f"airflow.sdk.definitions.macros.{plugin.name}", plugin.macros)
macros_module = make_module(f"airflow.sdk.execution_time.macros.{plugin.name}", plugin.macros)

if macros_module:
macros_modules.append(macros_module)
Expand Down
12 changes: 6 additions & 6 deletions airflow-core/tests/unit/plugins/test_plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ def test_registering_plugin_macros(self, request):
Tests whether macros that originate from plugins are being registered correctly.
"""
from airflow.plugins_manager import integrate_macros_plugins
from airflow.sdk.definitions import macros
from airflow.sdk.execution_time import macros

def cleanup_macros():
"""Reloads the macros module such that the symbol table is reset after the test."""
# We're explicitly deleting the module from sys.modules and importing it again
# using import_module() as opposed to using importlib.reload() because the latter
# does not undo the changes to the airflow.sdk.definitions.macros module that are being caused by
# does not undo the changes to the airflow.sdk.execution_time.macros module that are being caused by
# invoking integrate_macros_plugins()

del sys.modules["airflow.sdk.definitions.macros"]
importlib.import_module("airflow.sdk.definitions.macros")
del sys.modules["airflow.sdk.execution_time.macros"]
importlib.import_module("airflow.sdk.execution_time.macros")

request.addfinalizer(cleanup_macros)

Expand All @@ -254,12 +254,12 @@ class MacroPlugin(AirflowPlugin):
# Ensure the macros for the plugin have been integrated.
integrate_macros_plugins()
# Test whether the modules have been created as expected.
plugin_macros = importlib.import_module(f"airflow.sdk.definitions.macros.{MacroPlugin.name}")
plugin_macros = importlib.import_module(f"airflow.sdk.execution_time.macros.{MacroPlugin.name}")
for macro in MacroPlugin.macros:
# Verify that the macros added by the plugin are being set correctly
# on the plugin's macro module.
assert hasattr(plugin_macros, macro.__name__)
# Verify that the symbol table in airflow.sdk.definitions.macros has been updated with an entry for
# Verify that the symbol table in airflow.sdk.execution_time.macros has been updated with an entry for
# this plugin, this is necessary in order to allow the plugin's macros to be used when
# rendering templates.
assert hasattr(macros, MacroPlugin.name)
Expand Down
4 changes: 2 additions & 2 deletions task-sdk/src/airflow/sdk/execution_time/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ class MacrosAccessor:
def __getattr__(self, item: str) -> Any:
# Lazily load Macros module
if not self._macros_module:
import airflow.sdk.definitions.macros
import airflow.sdk.execution_time.macros

self._macros_module = airflow.sdk.definitions.macros
self._macros_module = airflow.sdk.execution_time.macros
return getattr(self._macros_module, item)

def __repr__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion task-sdk/tests/task_sdk/definitions/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import pendulum
import pytest

from airflow.sdk.definitions import macros
from airflow.sdk.execution_time import macros


@pytest.mark.parametrize(
Expand Down