Skip to content

Commit 0af388d

Browse files
committed
fixup! Remove flask-admin based Plugins
1 parent a729f7e commit 0af388d

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

airflow/plugins_manager.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
executors_modules: Optional[List[Any]] = None
4646

4747
# Plugin components to integrate directly
48+
admin_views: Optional[List[Any]] = None
4849
flask_blueprints: Optional[List[Any]] = None
50+
menu_links: Optional[List[Any]] = None
4951
flask_appbuilder_views: Optional[List[Any]] = None
5052
flask_appbuilder_menu_links: Optional[List[Any]] = None
5153
global_operator_extra_links: Optional[List[Any]] = None
@@ -71,7 +73,9 @@ class AirflowPlugin:
7173
hooks: List[Any] = []
7274
executors: List[Any] = []
7375
macros: List[Any] = []
76+
admin_views: List[Any] = []
7477
flask_blueprints: List[Any] = []
78+
menu_links: List[Any] = []
7579
appbuilder_views: List[Any] = []
7680
appbuilder_menu_items: List[Any] = []
7781

@@ -230,7 +234,6 @@ def initialize_web_ui_plugins():
230234
"""Collect extension points for WEB UI"""
231235
# pylint: disable=global-statement
232236
global plugins
233-
234237
global flask_blueprints
235238
global flask_appbuilder_views
236239
global flask_appbuilder_menu_links
@@ -260,6 +263,14 @@ def initialize_web_ui_plugins():
260263
'blueprint': bp
261264
} for bp in plugin.flask_blueprints])
262265

266+
if (plugin.admin_views and not plugin.appbuilder_views) or (
267+
plugin.menu_links and not plugin.appbuilder_menu_items):
268+
log.warning(
269+
"Plugin \'%s\' may not be compatible with the current Airflow version. "
270+
"Please contact the author of the plugin.",
271+
plugin.name
272+
)
273+
263274

264275
def initialize_extra_operators_links_plugins():
265276
"""Creates modules for loaded extension from extra operators links plugins"""

tests/plugins/test_plugins_manager.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,77 @@ class TestNonPropertyHook(BaseHook):
120120
self.assertIn('AirflowTestPropertyPlugin', str(plugins_manager.plugins))
121121
self.assertIn('PluginPropertyOperator', str(plugins_manager.operators_modules[0].__dict__))
122122
self.assertIn("TestNonPropertyHook", str(plugins_manager.hooks_modules[0].__dict__))
123+
124+
def test_should_warning_about_incompatible_plugins(self):
125+
class AirflowAdminViewsPlugin(AirflowPlugin):
126+
name = "test_admin_views_plugin"
127+
128+
admin_views = [mock.MagicMock()]
129+
130+
class AirflowAdminMenuLinksPlugin(AirflowPlugin):
131+
name = "test_menu_links_plugin"
132+
133+
menu_links = [mock.MagicMock()]
134+
135+
with mock_plugin_manager(plugins=[
136+
AirflowAdminViewsPlugin(),
137+
AirflowAdminMenuLinksPlugin()
138+
]):
139+
from airflow import plugins_manager
140+
141+
# assert not logs
142+
with self.assertLogs(plugins_manager.log) as cm:
143+
plugins_manager.initialize_web_ui_plugins()
144+
145+
self.assertEqual(cm.output, [
146+
'WARNING:airflow.plugins_manager:Plugin \'test_admin_views_plugin\' may not be '
147+
'compatible with the current Airflow version. Please contact the author of '
148+
'the plugin.',
149+
'WARNING:airflow.plugins_manager:Plugin \'test_menu_links_plugin\' may not be '
150+
'compatible with the current Airflow version. Please contact the author of '
151+
'the plugin.'
152+
])
153+
154+
def test_should_not_warning_about_fab_plugins(self):
155+
class AirflowAdminViewsPlugin(AirflowPlugin):
156+
name = "test_admin_views_plugin"
157+
158+
appbuilder_views = [mock.MagicMock()]
159+
160+
class AirflowAdminMenuLinksPlugin(AirflowPlugin):
161+
name = "test_menu_links_plugin"
162+
163+
appbuilder_menu_items = [mock.MagicMock()]
164+
165+
with mock_plugin_manager(plugins=[
166+
AirflowAdminViewsPlugin(),
167+
AirflowAdminMenuLinksPlugin()
168+
]):
169+
from airflow import plugins_manager
170+
171+
# assert not logs
172+
with self.assertRaises(AssertionError), self.assertLogs(plugins_manager.log):
173+
plugins_manager.initialize_web_ui_plugins()
174+
175+
def test_should_not_warning_about_fab_and_flask_admin_plugins(self):
176+
class AirflowAdminViewsPlugin(AirflowPlugin):
177+
name = "test_admin_views_plugin"
178+
179+
admin_views = [mock.MagicMock()]
180+
appbuilder_views = [mock.MagicMock()]
181+
182+
class AirflowAdminMenuLinksPlugin(AirflowPlugin):
183+
name = "test_menu_links_plugin"
184+
185+
menu_links = [mock.MagicMock()]
186+
appbuilder_menu_items = [mock.MagicMock()]
187+
188+
with mock_plugin_manager(plugins=[
189+
AirflowAdminViewsPlugin(),
190+
AirflowAdminMenuLinksPlugin()
191+
]):
192+
from airflow import plugins_manager
193+
194+
# assert not logs
195+
with self.assertRaises(AssertionError), self.assertLogs(plugins_manager.log):
196+
plugins_manager.initialize_web_ui_plugins()

tests/test_utils/mock_plugins.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"hooks_modules",
2626
"macros_modules",
2727
"executors_modules",
28+
"admin_views",
2829
"flask_blueprints",
30+
"menu_links",
2931
"flask_appbuilder_views",
3032
"flask_appbuilder_menu_links",
3133
"global_operator_extra_links",

0 commit comments

Comments
 (0)