Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue deprecation warning for plugins registering ti_deps #45742

Open
wants to merge 1 commit into
base: v2-10-test
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions airflow/plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import sys
import types
import warnings
from pathlib import Path
from typing import TYPE_CHECKING, Any, Iterable

Expand Down Expand Up @@ -431,6 +432,17 @@ def initialize_ti_deps_plugins():
registered_ti_dep_classes = {}

for plugin in plugins:
if not plugin.ti_deps:
continue

from airflow.exceptions import RemovedInAirflow3Warning

warnings.warn(
"Using custom `ti_deps` on operators has been removed in Airflow 3.0",
RemovedInAirflow3Warning,
stacklevel=1,
)

registered_ti_dep_classes.update(
{qualname(ti_dep.__class__): ti_dep.__class__ for ti_dep in plugin.ti_deps}
)
Expand Down
17 changes: 17 additions & 0 deletions tests/plugins/test_plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import pytest

from airflow.exceptions import RemovedInAirflow3Warning
from airflow.hooks.base import BaseHook
from airflow.listeners.listener import get_listener_manager
from airflow.plugins_manager import AirflowPlugin
Expand Down Expand Up @@ -174,6 +175,11 @@ def clean_plugins(self):

plugins_manager.loaded_plugins = set()
plugins_manager.plugins = []
yield
plugins_manager.loaded_plugins = set()

plugins_manager.registered_ti_dep_classes = None
plugins_manager.plugins = None

def test_no_log_when_no_plugins(self, caplog):
with mock_plugin_manager(plugins=[]):
Expand Down Expand Up @@ -270,6 +276,17 @@ class AirflowAdminMenuLinksPlugin(AirflowPlugin):
),
]

def test_deprecate_ti_deps(self):
class DeprecatedTIDeps(AirflowPlugin):
name = "ti_deps"

ti_deps = [mock.MagicMock()]

with mock_plugin_manager(plugins=[DeprecatedTIDeps()]), pytest.warns(RemovedInAirflow3Warning):
from airflow import plugins_manager

plugins_manager.initialize_ti_deps_plugins()

def test_should_not_warning_about_fab_plugins(self, caplog):
class AirflowAdminViewsPlugin(AirflowPlugin):
name = "test_admin_views_plugin"
Expand Down
3 changes: 3 additions & 0 deletions tests/serialization/test_dag_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ def sorted_serialized_dag(dag_dict: dict):
return actual, expected

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

Expand Down Expand Up @@ -1596,6 +1597,7 @@ def test_deps_sorted(self):
"airflow.ti_deps.deps.trigger_rule_dep.TriggerRuleDep",
]

@pytest.mark.filterwarnings("ignore::airflow.exceptions.RemovedInAirflow3Warning")
def test_error_on_unregistered_ti_dep_serialization(self):
# trigger rule not registered through the plugin system will not be serialized
class DummyTriggerRule(BaseTIDep):
Expand Down Expand Up @@ -1634,6 +1636,7 @@ def test_error_on_unregistered_ti_dep_deserialization(self):
SerializedBaseOperator.deserialize_operator(serialize_op)

@pytest.mark.db_test
@pytest.mark.filterwarnings("ignore::airflow.exceptions.RemovedInAirflow3Warning")
def test_serialize_and_deserialize_custom_ti_deps(self):
from test_plugin import CustomTestTriggerRule

Expand Down
Loading