Skip to content

Commit 7d02211

Browse files
authored
Replace DeprecationWarning with DeprecatedImportWarning in airflow-core (apache#56836)
1 parent 310f268 commit 7d02211

File tree

10 files changed

+27
-10
lines changed

10 files changed

+27
-10
lines changed

airflow-core/src/airflow/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import warnings
3434
from typing import TYPE_CHECKING
3535

36+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
37+
3638
if os.environ.get("_AIRFLOW_PATCH_GEVENT"):
3739
# If you are using gevents and start airflow webserver, you might want to run gevent monkeypatching
3840
# as one of the first thing when Airflow is started. This allows gevent to patch networking and other
@@ -105,7 +107,7 @@ def __getattr__(name: str):
105107
warnings.warn(
106108
f"Import {name!r} directly from the airflow module is deprecated and "
107109
f"will be removed in the future. Please import it from 'airflow{module_path}.{attr_name}'.",
108-
DeprecationWarning,
110+
DeprecatedImportWarning,
109111
stacklevel=2,
110112
)
111113

airflow-core/src/airflow/datasets/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import importlib
2828
import warnings
2929

30+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
31+
3032
# TODO: Remove this module in Airflow 3.2
3133

3234
_names_moved = {
@@ -47,7 +49,7 @@ def __getattr__(name: str):
4749
warnings.warn(
4850
f"Import 'airflow.datasets.{name}' is deprecated and "
4951
f"will be removed in Airflow 3.2. Please import it from '{module_path}.{new_name}'.",
50-
DeprecationWarning,
52+
DeprecatedImportWarning,
5153
stacklevel=2,
5254
)
5355
mod = importlib.import_module(module_path, __name__)

airflow-core/src/airflow/datasets/metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
import warnings
2121

2222
from airflow.sdk import Metadata
23+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
2324

2425
# TODO: Remove this module in Airflow 3.2
2526

2627
warnings.warn(
2728
"Import from the airflow.datasets.metadata module is deprecated and will "
2829
"be removed in Airflow 3.2. Please import it from 'airflow.sdk'.",
29-
DeprecationWarning,
30+
DeprecatedImportWarning,
3031
stacklevel=2,
3132
)
3233

airflow-core/src/airflow/models/dag.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,12 @@ def __getattr__(name: str):
750750

751751
import warnings
752752

753+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
754+
753755
warnings.warn(
754756
f"Import {name!r} directly from the airflow module is deprecated and "
755757
f"will be removed in the future. Please import it from 'airflow.sdk'.",
756-
DeprecationWarning,
758+
DeprecatedImportWarning,
757759
stacklevel=2,
758760
)
759761

airflow-core/src/airflow/models/dagbag.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ def __getattr__(name: str) -> Any:
146146
if name in {"DagBag", "FileLoadStat", "timeout"}:
147147
import warnings
148148

149+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
150+
149151
warnings.warn(
150152
f"Importing {name} from airflow.models.dagbag is deprecated and will be removed in a future "
151153
"release. Please import from airflow.dag_processing.dagbag instead.",
152-
DeprecationWarning,
154+
DeprecatedImportWarning,
153155
stacklevel=2,
154156
)
155157
# Import on demand to avoid import-time side effects

airflow-core/src/airflow/secrets/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ def __getattr__(name):
5151
if name == "DEFAULT_SECRETS_SEARCH_PATH_WORKERS":
5252
import warnings
5353

54+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
55+
5456
warnings.warn(
5557
"airflow.secrets.DEFAULT_SECRETS_SEARCH_PATH_WORKERS is moved to the Task SDK. "
5658
"Use airflow.sdk.execution_time.secrets.DEFAULT_SECRETS_SEARCH_PATH_WORKERS instead.",
57-
DeprecationWarning,
59+
DeprecatedImportWarning,
5860
stacklevel=2,
5961
)
6062
try:

airflow-core/src/airflow/timetables/datasets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import warnings
2020

2121
from airflow.timetables.assets import AssetOrTimeSchedule
22+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
2223

2324

2425
class DatasetOrTimeSchedule:
@@ -27,7 +28,7 @@ class DatasetOrTimeSchedule:
2728
def __new__(cls, *, timetable, datasets) -> AssetOrTimeSchedule: # type: ignore[misc]
2829
warnings.warn(
2930
"DatasetOrTimeSchedule is deprecated and will be removed in Airflow 3.2. Use `airflow.timetables.AssetOrTimeSchedule` instead.",
30-
DeprecationWarning,
31+
DeprecatedImportWarning,
3132
stacklevel=2,
3233
)
3334
return AssetOrTimeSchedule(timetable=timetable, assets=datasets)

airflow-core/src/airflow/utils/dag_parsing_context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121

2222
from airflow.sdk.definitions._internal.dag_parsing_context import _airflow_parsing_context_manager
2323
from airflow.sdk.definitions.context import get_parsing_context
24+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
2425

2526
# TODO: Remove this module in Airflow 3.2
2627

2728
warnings.warn(
2829
"Import from the airflow.utils.dag_parsing_context module is deprecated and "
2930
"will be removed in Airflow 3.2. Please import it from 'airflow.sdk'.",
30-
DeprecationWarning,
31+
DeprecatedImportWarning,
3132
stacklevel=2,
3233
)
3334

airflow-core/tests/unit/core/test_airflow_module.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424

2525
def test_deprecated_exception():
26+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
27+
2628
warning_pattern = "Import 'AirflowException' directly from the airflow module is deprecated"
27-
with pytest.warns(DeprecationWarning, match=warning_pattern):
29+
with pytest.warns(DeprecatedImportWarning, match=warning_pattern):
2830
# If there is no warning, then most possible it imported somewhere else.
2931
assert getattr(airflow, "AirflowException") is AirflowException

airflow-core/tests/unit/datasets/test_dataset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def test_backward_compat_import_before_airflow_3_2(module_path, attr_name, expec
8484
mod = importlib.import_module(module_path, __name__)
8585
attr = getattr(mod, attr_name)
8686
assert f"{attr.__module__}.{attr.__name__}" == expected_value
87-
assert record[0].category is DeprecationWarning
87+
from airflow.utils.deprecation_tools import DeprecatedImportWarning
88+
89+
assert record[0].category is DeprecatedImportWarning
8890
assert str(record[0].message) == warning_message
8991

9092

0 commit comments

Comments
 (0)