You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2021/07/23 18:27:05 UTC

[airflow] branch main updated: Only allows supported field types to be used in custom connections (#17194)

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

potiuk 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 8e94c1c  Only allows supported field types to be used in custom connections (#17194)
8e94c1c is described below

commit 8e94c1c64902b97be146cdcfe8b721fced0a283b
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Fri Jul 23 20:26:51 2021 +0200

    Only allows supported field types to be used in custom connections (#17194)
    
    * Only allows supported field types to be used in custom connections
    
    Only four field types are supported in Connection Forms:
    String, Password, Integer, Boolean.
    
    Previously when custom connections tried to use other field
    type, ConnectionForm behaved in a very strange way - the
    connection form reloaded quickly hiding the actual error
    and no error was printed making it next to impossible to figure
    out the root cause of the problem.
    
    With this change, non-supported field types generate Warning
    and the Connections that use them are not added to the list of
    supported connections.
    
    Fixes: #17193
---
 airflow/providers_manager.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/airflow/providers_manager.py b/airflow/providers_manager.py
index 0770f24..5e67e06 100644
--- a/airflow/providers_manager.py
+++ b/airflow/providers_manager.py
@@ -25,7 +25,7 @@ from collections import OrderedDict
 from typing import Any, Dict, NamedTuple, Set
 
 import jsonschema
-from wtforms import Field
+from wtforms import BooleanField, Field, IntegerField, PasswordField, StringField
 
 from airflow.utils import yaml
 from airflow.utils.entry_points import entry_points_with_dist
@@ -36,6 +36,8 @@ except ImportError:
     # Try back-ported to PY<37 `importlib_resources`.
     import importlib_resources
 
+ALLOWED_FIELD_CLASSES = [IntegerField, PasswordField, StringField, BooleanField]
+
 log = logging.getLogger(__name__)
 
 
@@ -274,6 +276,16 @@ class ProvidersManager:
             if 'get_connection_form_widgets' in hook_class.__dict__:
                 widgets = hook_class.get_connection_form_widgets()
                 if widgets:
+                    for widget in widgets.values():
+                        if widget.field_class not in ALLOWED_FIELD_CLASSES:
+                            log.warning(
+                                "The hook_class '%s' uses field of unsupported class '%s'. "
+                                "Only '%s' field classes are supported",
+                                hook_class_name,
+                                widget.field_class,
+                                ALLOWED_FIELD_CLASSES,
+                            )
+                            return
                     self._add_widgets(provider_package, hook_class, widgets)
             if 'get_ui_field_behaviour' in hook_class.__dict__:
                 field_behaviours = hook_class.get_ui_field_behaviour()