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

Fix get_plugin_info for class based listeners. #35022

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
6 changes: 4 additions & 2 deletions airflow/plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,10 @@ def get_plugin_info(attrs_to_dump: Iterable[str] | None = None) -> list[dict[str
elif attr in ("macros", "timetables", "hooks", "executors"):
info[attr] = [qualname(d) for d in getattr(plugin, attr)]
elif attr == "listeners":
# listeners are always modules
info[attr] = [d.__name__ for d in getattr(plugin, attr)]
# listeners may be modules or class instances
info[attr] = [
d.__name__ if inspect.ismodule(d) else qualname(d) for d in getattr(plugin, attr)
]
elif attr == "appbuilder_views":
info[attr] = [
{**d, "view": qualname(d["view"].__class__) if "view" in d else None}
Expand Down
5 changes: 4 additions & 1 deletion tests/cli/commands/test_plugins_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def test_should_display_one_plugins(self):
"<tests.test_utils.mock_operators.CustomBaseIndexOpLink object>",
],
"hooks": ["tests.plugins.test_plugin.PluginHook"],
"listeners": ["tests.listeners.empty_listener"],
"listeners": [
"tests.listeners.empty_listener",
"tests.listeners.class_listener.ClassBasedListener",
],
"source": None,
"appbuilder_menu_items": [
{"name": "Google", "href": "https://www.google.com", "category": "Search"},
Expand Down
3 changes: 2 additions & 1 deletion tests/plugins/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from airflow.ti_deps.deps.base_ti_dep import BaseTIDep
from airflow.timetables.interval import CronDataIntervalTimetable
from tests.listeners import empty_listener
from tests.listeners.class_listener import ClassBasedListener
from tests.test_utils.mock_operators import (
AirflowLink,
AirflowLink2,
Expand Down Expand Up @@ -129,7 +130,7 @@ class AirflowTestPlugin(AirflowPlugin):
]
operator_extra_links = [GoogleLink(), AirflowLink2(), CustomOpLink(), CustomBaseIndexOpLink(1)]
timetables = [CustomCronDataIntervalTimetable]
listeners = [empty_listener]
listeners = [empty_listener, ClassBasedListener()]
ti_deps = [CustomTestTriggerRule()]


Expand Down
10 changes: 9 additions & 1 deletion tests/plugins/test_plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import annotations

import importlib
import inspect
import logging
import os
import sys
Expand All @@ -29,6 +30,7 @@
from airflow.hooks.base import BaseHook
from airflow.listeners.listener import get_listener_manager
from airflow.plugins_manager import AirflowPlugin
from airflow.utils.module_loading import qualname
from airflow.www import app as application
from setup import AIRFLOW_SOURCES_ROOT
from tests.test_utils.config import conf_vars
Expand Down Expand Up @@ -379,7 +381,13 @@ def test_registering_plugin_listeners(self):
plugins_manager.integrate_listener_plugins(get_listener_manager())

assert get_listener_manager().has_listeners
assert get_listener_manager().pm.get_plugins().pop().__name__ == "tests.listeners.empty_listener"
listeners = get_listener_manager().pm.get_plugins()
listener_names = [el.__name__ if inspect.ismodule(el) else qualname(el) for el in listeners]
# sort names as order of listeners is not guaranteed
assert [
"tests.listeners.class_listener.ClassBasedListener",
"tests.listeners.empty_listener",
] == sorted(listener_names)

def test_should_import_plugin_from_providers(self):
from airflow import plugins_manager
Expand Down
Loading