Skip to content

Commit

Permalink
Fix connection test button (#23345)
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit f197030)
  • Loading branch information
jedcunningham authored and ephraimbuddy committed May 8, 2022
1 parent 1a76639 commit f50ef22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3867,8 +3867,8 @@ def field_behaviours(self):
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
]


Expand Down
13 changes: 12 additions & 1 deletion tests/www/views/test_views_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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 = {
Expand Down Expand Up @@ -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

0 comments on commit f50ef22

Please sign in to comment.