This is an automated email from the ASF dual-hosted git repository.
amoghdesai 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 00d6777573e Deprecate get_connection_form_widgets &
get_ui_field_behaviour hook methods (#63711)
00d6777573e is described below
commit 00d6777573e959e4b0bf9059220344b011dff680
Author: Amogh Desai <[email protected]>
AuthorDate: Tue Mar 17 15:24:05 2026 +0530
Deprecate get_connection_form_widgets & get_ui_field_behaviour hook methods
(#63711)
---
airflow-core/src/airflow/providers_manager.py | 18 +++++++++-
.../tests/unit/always/test_providers_manager.py | 39 ++++++++++++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/airflow-core/src/airflow/providers_manager.py
b/airflow-core/src/airflow/providers_manager.py
index 544311c4701..a28f1bd9274 100644
--- a/airflow-core/src/airflow/providers_manager.py
+++ b/airflow-core/src/airflow/providers_manager.py
@@ -36,7 +36,7 @@ from typing import TYPE_CHECKING, Any, NamedTuple, ParamSpec,
TypeVar, cast
from airflow import DeprecatedImportWarning
from airflow._shared.module_loading import import_string
from airflow._shared.providers_discovery import
discover_all_providers_from_packages
-from airflow.exceptions import AirflowOptionalProviderFeatureException
+from airflow.exceptions import AirflowOptionalProviderFeatureException,
AirflowProviderDeprecationWarning
from airflow.utils.log.logging_mixin import LoggingMixin
if TYPE_CHECKING:
@@ -1061,6 +1061,14 @@ class ProvidersManager(LoggingMixin):
# inherited from parent hook. This way we add form fields only
once for the whole
# hierarchy and we add it only from the parent hook that
provides those!
if "get_connection_form_widgets" in hook_class.__dict__:
+ warning = AirflowProviderDeprecationWarning(
+ f"Hook '{hook_class_name}' defines
get_connection_form_widgets(). "
+ "This method is deprecated. Define connection fields
declaratively in "
+ "provider.yaml under 'conn-fields' instead. See "
+
"https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html"
+ )
+ warning.deprecated_provider_since = "3.2.0"
+ warnings.warn(warning, stacklevel=2)
widgets = hook_class.get_connection_form_widgets()
if widgets:
for widget in widgets.values():
@@ -1075,6 +1083,14 @@ class ProvidersManager(LoggingMixin):
return None
self._add_widgets_from_hook(package_name, hook_class,
widgets)
if "get_ui_field_behaviour" in hook_class.__dict__:
+ warning = AirflowProviderDeprecationWarning(
+ f"Hook '{hook_class_name}' defines
get_ui_field_behaviour(). "
+ "This method is deprecated. Define field behaviour
declaratively in "
+ "provider.yaml under 'ui-field-behaviour' instead. See
"
+
"https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html"
+ )
+ warning.deprecated_provider_since = "3.2.0"
+ warnings.warn(warning, stacklevel=2)
field_behaviours = hook_class.get_ui_field_behaviour()
if field_behaviours:
self._add_customized_fields_from_hook(package_name,
hook_class, field_behaviours)
diff --git a/airflow-core/tests/unit/always/test_providers_manager.py
b/airflow-core/tests/unit/always/test_providers_manager.py
index 531442395e3..7b691965012 100644
--- a/airflow-core/tests/unit/always/test_providers_manager.py
+++ b/airflow-core/tests/unit/always/test_providers_manager.py
@@ -23,6 +23,9 @@ import sys
from collections.abc import Callable
from typing import TYPE_CHECKING
+from airflow.exceptions import AirflowProviderDeprecationWarning
+from airflow.sdk import BaseHook
+
PY313 = sys.version_info >= (3, 13)
from unittest.mock import patch
@@ -435,3 +438,39 @@ class TestProvidersMetadataLoading:
# assert that HttpHook was not imported during initialization,
which means yaml path was taken
assert len([call for call in mock_import.call_args_list if
"HttpHook" in str(call)]) == 0
+
+ def test_deprecated_hook_methods_emit_warnings(self):
+ """Test that hooks using Python methods emit
AirflowProviderDeprecationWarning."""
+
+ class MockDeprecatedHook(BaseHook):
+ conn_type = "mock_deprecated"
+
+ @staticmethod
+ def get_connection_form_widgets():
+ from wtforms import StringField
+
+ return {"test_field": StringField("Test Field")}
+
+ @staticmethod
+ def get_ui_field_behaviour():
+ return {"hidden_fields": ["schema"]}
+
+ pm = ProvidersManager()
+
+ with patch("airflow.providers_manager.import_string",
return_value=MockDeprecatedHook):
+ with pytest.warns(
+ AirflowProviderDeprecationWarning,
match="get_connection_form_widgets"
+ ) as widgets_warning:
+ with pytest.warns(
+ AirflowProviderDeprecationWarning,
match="get_ui_field_behaviour"
+ ) as behaviour_warning:
+ pm._import_hook(
+ connection_type=None,
+ provider_info=None,
+ hook_class_name="test.MockDeprecatedHook",
+ package_name="test-provider",
+ )
+
+ # Validate deprecated_provider_since is set correctly
+ assert widgets_warning[0].message.deprecated_provider_since ==
"3.2.0"
+ assert behaviour_warning[0].message.deprecated_provider_since ==
"3.2.0"