You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by as...@apache.org on 2022/04/29 10:29:28 UTC

[airflow] branch main updated: Fix connection test button (#23345)

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

ash pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new f197030cea Fix connection test button (#23345)
f197030cea is described below

commit f197030cea860351da07894879f647fe76c5751e
Author: Jed Cunningham <66...@users.noreply.github.com>
AuthorDate: Fri Apr 29 04:29:02 2022 -0600

    Fix connection test button (#23345)
    
    The connection test button was always disabled if any of your hooks had
    import errors, for example because of a missing module. This handles
    that scenario.
---
 airflow/www/views.py                     |  4 ++--
 tests/www/views/test_views_connection.py | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/airflow/www/views.py b/airflow/www/views.py
index 8979789dcb..dba03500fd 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -3859,8 +3859,8 @@ class ConnectionFormWidget(FormWidget):
     def testable_connection_types(self):
         return [
             connection_type
-            for connection_type, provider_info in ProvidersManager().hooks.items()
-            if provider_info.connection_testable
+            for connection_type, hook_info in ProvidersManager().hooks.items()
+            if hook_info and hook_info.connection_testable
         ]
 
 
diff --git a/tests/www/views/test_views_connection.py b/tests/www/views/test_views_connection.py
index 8c5ff0d013..d71a8a63c0 100644
--- a/tests/www/views/test_views_connection.py
+++ b/tests/www/views/test_views_connection.py
@@ -25,7 +25,7 @@ from pytest import param
 from airflow.models import Connection
 from airflow.utils.session import create_session
 from airflow.www.extensions import init_views
-from airflow.www.views import ConnectionModelView
+from airflow.www.views import ConnectionFormWidget, ConnectionModelView
 from tests.test_utils.www import check_content_in_response
 
 CONNECTION = {
@@ -311,3 +311,14 @@ def test_connection_muldelete(admin_client, connection):
     assert resp.status_code == 200
     with create_session() as session:
         assert session.query(Connection).filter(Connection.id == conn_id).count() == 0
+
+
+@mock.patch('airflow.providers_manager.ProvidersManager.hooks', new_callable=PropertyMock)
+def test_connection_form_widgets_testable_types(mock_pm_hooks, admin_client):
+    mock_pm_hooks.return_value = {
+        "first": mock.MagicMock(connection_testable=True),
+        "second": mock.MagicMock(connection_testable=False),
+        "third": None,
+    }
+
+    assert ["first"] == ConnectionFormWidget().testable_connection_types