Skip to content

Commit 4429f06

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

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
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

+12
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
@@ -270,6 +271,17 @@ class AirflowAdminMenuLinksPlugin(AirflowPlugin):
270271
),
271272
]
272273

274+
def test_deprecate_ti_deps(self):
275+
class DeprecatedTIDeps(AirflowPlugin):
276+
name = "ti_deps"
277+
278+
ti_deps = [mock.MagicMock()]
279+
280+
with mock_plugin_manager(plugins=[DeprecatedTIDeps()]), pytest.warns(RemovedInAirflow3Warning):
281+
from airflow import plugins_manager
282+
283+
plugins_manager.initialize_ti_deps_plugins()
284+
273285
def test_should_not_warning_about_fab_plugins(self, caplog):
274286
class AirflowAdminViewsPlugin(AirflowPlugin):
275287
name = "test_admin_views_plugin"

tests/serialization/test_dag_serialization.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ class DummyTask(BaseOperator):
16121612
) as dag:
16131613
DummyTask(task_id="task1")
16141614

1615-
with pytest.raises(SerializationError):
1615+
with pytest.raises(SerializationError), pytest.warns(RemovedInAirflow3Warning):
16161616
SerializedBaseOperator.serialize_operator(dag.task_dict["task1"])
16171617

16181618
def test_error_on_unregistered_ti_dep_deserialization(self):
@@ -1644,7 +1644,8 @@ class DummyTask(BaseOperator):
16441644
with DAG(dag_id="test_serialize_custom_ti_deps", schedule=None, start_date=execution_date) as dag:
16451645
DummyTask(task_id="task1")
16461646

1647-
serialize_op = SerializedBaseOperator.serialize_operator(dag.task_dict["task1"])
1647+
with pytest.warns(RemovedInAirflow3Warning):
1648+
serialize_op = SerializedBaseOperator.serialize_operator(dag.task_dict["task1"])
16481649

16491650
assert serialize_op["deps"] == [
16501651
"airflow.ti_deps.deps.mapped_task_upstream_dep.MappedTaskUpstreamDep",

0 commit comments

Comments
 (0)