Skip to content

Commit 030cdaa

Browse files
committed
Issue deprecation warning for plugins registering ti_deps
This is removed in Airflow3 via #45713
1 parent 04d0381 commit 030cdaa

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

airflow/plugins_manager.py

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import os
2828
import sys
2929
import types
30+
import warnings
3031
from pathlib import Path
3132
from typing import TYPE_CHECKING, Any, Iterable
3233

@@ -431,6 +432,17 @@ def initialize_ti_deps_plugins():
431432
registered_ti_dep_classes = {}
432433

433434
for plugin in plugins:
435+
if not plugin.ti_deps:
436+
continue
437+
438+
from airflow.exceptions import RemovedInAirflow3Warning
439+
440+
warnings.warn(
441+
"Using custom `ti_deps` on operators has been removed in Airflow 3.0",
442+
RemovedInAirflow3Warning,
443+
stacklevel=1,
444+
)
445+
434446
registered_ti_dep_classes.update(
435447
{qualname(ti_dep.__class__): ti_dep.__class__ for ti_dep in plugin.ti_deps}
436448
)

tests/plugins/test_plugins_manager.py

+17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import pytest
3030

31+
from airflow.exceptions import RemovedInAirflow3Warning
3132
from airflow.hooks.base import BaseHook
3233
from airflow.listeners.listener import get_listener_manager
3334
from airflow.plugins_manager import AirflowPlugin
@@ -174,6 +175,11 @@ def clean_plugins(self):
174175

175176
plugins_manager.loaded_plugins = set()
176177
plugins_manager.plugins = []
178+
yield
179+
plugins_manager.loaded_plugins = set()
180+
181+
plugins_manager.registered_ti_dep_classes = None
182+
plugins_manager.plugins = None
177183

178184
def test_no_log_when_no_plugins(self, caplog):
179185
with mock_plugin_manager(plugins=[]):
@@ -270,6 +276,17 @@ class AirflowAdminMenuLinksPlugin(AirflowPlugin):
270276
),
271277
]
272278

279+
def test_deprecate_ti_deps(self):
280+
class DeprecatedTIDeps(AirflowPlugin):
281+
name = "ti_deps"
282+
283+
ti_deps = [mock.MagicMock()]
284+
285+
with mock_plugin_manager(plugins=[DeprecatedTIDeps()]), pytest.warns(RemovedInAirflow3Warning):
286+
from airflow import plugins_manager
287+
288+
plugins_manager.initialize_ti_deps_plugins()
289+
273290
def test_should_not_warning_about_fab_plugins(self, caplog):
274291
class AirflowAdminViewsPlugin(AirflowPlugin):
275292
name = "test_admin_views_plugin"

tests/serialization/test_dag_serialization.py

+4
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def setup_test_cases(self):
430430
)
431431

432432
@pytest.mark.db_test
433+
@pytest.mark.filterwarnings("ignore::airflow.exceptions.RemovedInAirflow3Warning")
433434
def test_serialization(self):
434435
"""Serialization and deserialization should work for every DAG and Operator."""
435436
dags = collect_dags()
@@ -539,6 +540,7 @@ def sorted_serialized_dag(dag_dict: dict):
539540
return actual, expected
540541

541542
@pytest.mark.db_test
543+
@pytest.mark.filterwarnings("ignore::airflow.exceptions.RemovedInAirflow3Warning")
542544
def test_deserialization_across_process(self):
543545
"""A serialized DAG can be deserialized in another process."""
544546

@@ -1596,6 +1598,7 @@ def test_deps_sorted(self):
15961598
"airflow.ti_deps.deps.trigger_rule_dep.TriggerRuleDep",
15971599
]
15981600

1601+
@pytest.mark.filterwarnings("ignore::airflow.exceptions.RemovedInAirflow3Warning")
15991602
def test_error_on_unregistered_ti_dep_serialization(self):
16001603
# trigger rule not registered through the plugin system will not be serialized
16011604
class DummyTriggerRule(BaseTIDep):
@@ -1634,6 +1637,7 @@ def test_error_on_unregistered_ti_dep_deserialization(self):
16341637
SerializedBaseOperator.deserialize_operator(serialize_op)
16351638

16361639
@pytest.mark.db_test
1640+
@pytest.mark.filterwarnings("ignore::airflow.exceptions.RemovedInAirflow3Warning")
16371641
def test_serialize_and_deserialize_custom_ti_deps(self):
16381642
from test_plugin import CustomTestTriggerRule
16391643

0 commit comments

Comments
 (0)