This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new bb3e71da466 Fix deprecated imports resolution in airflow.utils.helpers
(#71691)
bb3e71da466 is described below
commit bb3e71da4669dc0323eda3651dac18a9eed57275
Author: Shikhar Goel <[email protected]>
AuthorDate: Thu Sep 10 12:32:31 2026 +0530
Fix deprecated imports resolution in airflow.utils.helpers (#71691)
Co-authored-by: Shikhar Goel
<[email protected]>
---
airflow-core/src/airflow/utils/helpers.py | 4 +++-
airflow-core/tests/unit/utils/test_helpers.py | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/airflow-core/src/airflow/utils/helpers.py
b/airflow-core/src/airflow/utils/helpers.py
index d6463faea19..e67f7a509af 100644
--- a/airflow-core/src/airflow/utils/helpers.py
+++ b/airflow-core/src/airflow/utils/helpers.py
@@ -311,6 +311,7 @@ def __getattr__(name: str):
except KeyError:
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
from None
+ import importlib
import warnings
warnings.warn(
@@ -318,4 +319,5 @@ def __getattr__(name: str):
DeprecationWarning,
stacklevel=2,
)
- return getattr(__import__(modpath), name)
+ mod = importlib.import_module(modpath)
+ return getattr(mod, name)
diff --git a/airflow-core/tests/unit/utils/test_helpers.py
b/airflow-core/tests/unit/utils/test_helpers.py
index 944abd48c93..7136db3c149 100644
--- a/airflow-core/tests/unit/utils/test_helpers.py
+++ b/airflow-core/tests/unit/utils/test_helpers.py
@@ -241,6 +241,29 @@ class TestHelpers:
d2 = {"a": None, "b": "", "c": d1, "d": l1, "e": [None, "", 0, d1, l1,
[""]], "f": {}, "g": [""]}
assert prune_dict(d2, mode=mode) == expected
+ @pytest.mark.parametrize(
+ ("func_name", "target_module"),
+ [
+ ("render_template_as_native", "airflow.sdk.definitions.context"),
+ ("render_template_to_string", "airflow.sdk.definitions.context"),
+ ("prevent_duplicates", "airflow.sdk.definitions.mappedoperator"),
+ ],
+ )
+ def test_deprecated_imports(self, func_name, target_module):
+ import importlib
+
+ with pytest.deprecated_call():
+ imported_func = getattr(helpers, func_name)
+ target_mod = importlib.import_module(target_module)
+ expected_func = getattr(target_mod, func_name)
+ assert imported_func is expected_func
+
+ def test_deprecated_imports_unknown_attribute(self):
+ with pytest.raises(
+ AttributeError, match="module 'airflow.utils.helpers' has no
attribute 'non_existent_func'"
+ ):
+ _ = helpers.non_existent_func
+
class MockJobRunner(BaseJobRunner):
job_type = "MockJob"