You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/03/09 15:21:51 UTC

[airflow] branch v1-10-stable updated: Bugfix: False positives for Custom Executors via Plugins check (#14680)

This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-stable
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v1-10-stable by this push:
     new 08c015f  Bugfix: False positives for Custom Executors via Plugins check (#14680)
08c015f is described below

commit 08c015f56b4006fb7f77f4bce0394f804b2803b8
Author: Kaxil Naik <ka...@gmail.com>
AuthorDate: Tue Mar 9 15:21:37 2021 +0000

    Bugfix: False positives for Custom Executors via Plugins check (#14680)
    
    closes https://github.com/apache/airflow/issues/14311
---
 .../custom_executors_require_full_path_rule.py     | 13 ++++++++---
 ...test_custom_executors_require_full_path_rule.py | 27 ++++++++++++++++++----
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/airflow/upgrade/rules/custom_executors_require_full_path_rule.py b/airflow/upgrade/rules/custom_executors_require_full_path_rule.py
index af19543..55e9d5d 100644
--- a/airflow/upgrade/rules/custom_executors_require_full_path_rule.py
+++ b/airflow/upgrade/rules/custom_executors_require_full_path_rule.py
@@ -29,8 +29,15 @@ To load a custom executor, you have to provide a full path to the the custom exe
                   """
 
     def check(self):
-        from airflow.plugins_manager import executors_modules
-        if executors_modules:
+        from airflow.plugins_manager import plugins
+        executors_via_plugins = []
+
+        for plugin in plugins:
+            if plugin.executors:
+                for executor in plugin.executors:
+                    executors_via_plugins.append(executor.__name__)
+
+        if executors_via_plugins:
             return (
                 "Deprecation Warning: Found Custom Executor imported via a plugin."
                 "From Airflow 2.0, you should use regular Python Modules to import Custom Executor."
@@ -39,5 +46,5 @@ To load a custom executor, you have to provide a full path to the the custom exe
                 "https://github.com/apache/airflow/blob/2.0.0/"
                 "UPDATING.md#custom-executors-is-loaded-using-full-import-path \n"
                 "Following Executors were imported using Plugins: \n"
-                "{}".format(executors_modules)
+                "{}".format(executors_via_plugins)
             )
diff --git a/tests/upgrade/rules/test_custom_executors_require_full_path_rule.py b/tests/upgrade/rules/test_custom_executors_require_full_path_rule.py
index f1674ea..c1cf6e3 100644
--- a/tests/upgrade/rules/test_custom_executors_require_full_path_rule.py
+++ b/tests/upgrade/rules/test_custom_executors_require_full_path_rule.py
@@ -17,13 +17,32 @@
 
 from unittest import TestCase
 
+from airflow.executors import BaseExecutor
+from airflow.plugins_manager import AirflowPlugin
 from airflow.upgrade.rules.custom_executors_require_full_path_rule import CustomExecutorsRequireFullPathRule
 from tests.compat import patch
 
 
+class PluginExecutor(BaseExecutor):
+    pass
+
+
+class MyCustomExecutor(BaseExecutor):
+    pass
+
+
+class AirflowTestPlugin(AirflowPlugin):
+    name = "my_plugin"
+    executors = [PluginExecutor, MyCustomExecutor]
+
+
+class AirflowTestPlugin2(AirflowPlugin):
+    name = "my_plugin"
+
+
 class TestCustomExecutorsRequireFullPath(TestCase):
-    @patch('airflow.plugins_manager.executors_modules',
-           ["my_plugin.MyCustomExecutor", "my_acme.executors.MyCustomExecutor"])
+
+    @patch('airflow.plugins_manager.plugins', [AirflowTestPlugin])
     def test_invalid_check(self):
         rule = CustomExecutorsRequireFullPathRule()
 
@@ -38,12 +57,12 @@ class TestCustomExecutorsRequireFullPath(TestCase):
             "https://github.com/apache/airflow/blob/2.0.0/"
             "UPDATING.md#custom-executors-is-loaded-using-full-import-path \n"
             "Following Executors were imported using Plugins: \n"
-            "['my_plugin.MyCustomExecutor', 'my_acme.executors.MyCustomExecutor']"
+            "['PluginExecutor', 'MyCustomExecutor']"
         )
 
         assert msg == rule.check()
 
-    @patch('airflow.plugins_manager.executors_modules', [])
+    @patch('airflow.plugins_manager.plugins', [AirflowTestPlugin2])
     def test_check(self):
         rule = CustomExecutorsRequireFullPathRule()