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 2022/11/07 02:12:26 UTC

[airflow] branch main updated: Add warning if connection type already registered within the provider (#27520)

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 8458fec1c9 Add warning if connection type already registered within the provider (#27520)
8458fec1c9 is described below

commit 8458fec1c9435ab54eba1863d69f2bb618db0af3
Author: Andrey Anshin <An...@taragol.is>
AuthorDate: Mon Nov 7 06:12:19 2022 +0400

    Add warning if connection type already registered within the provider (#27520)
---
 airflow/providers_manager.py         |  9 +++++++++
 tests/core/test_providers_manager.py | 28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/airflow/providers_manager.py b/airflow/providers_manager.py
index 2e879fbc11..2b76db9078 100644
--- a/airflow/providers_manager.py
+++ b/airflow/providers_manager.py
@@ -564,6 +564,15 @@ class ProvidersManager(LoggingMixin):
                 if already_registered:
                     if already_registered.package_name != package_name:
                         already_registered_warning_connection_types.add(connection_type)
+                    else:
+                        log.warning(
+                            "The connection type '%s' is already registered in the"
+                            " package '%s' with different class names: '%s' and '%s'. ",
+                            connection_type,
+                            package_name,
+                            already_registered.hook_class_name,
+                            hook_class_name,
+                        )
                 else:
                     self._hook_provider_dict[connection_type] = HookClassProvider(
                         hook_class_name=hook_class_name, package_name=package_name
diff --git a/tests/core/test_providers_manager.py b/tests/core/test_providers_manager.py
index bbbf7944bf..044fe33ab2 100644
--- a/tests/core/test_providers_manager.py
+++ b/tests/core/test_providers_manager.py
@@ -123,6 +123,34 @@ class TestProviderManager:
         assert not self._caplog.records
         assert "sftp" in providers_manager.hooks
 
+    def test_already_registered_conn_type_in_provide(self):
+        with self._caplog.at_level(logging.WARNING):
+            providers_manager = ProvidersManager()
+            providers_manager._provider_dict["apache-airflow-providers-dummy"] = ProviderInfo(
+                version="0.0.1",
+                data={
+                    "connection-types": [
+                        {
+                            "hook-class-name": "airflow.providers.dummy.hooks.dummy.DummyHook",
+                            "connection-type": "dummy",
+                        },
+                        {
+                            "hook-class-name": "airflow.providers.dummy.hooks.dummy.DummyHook2",
+                            "connection-type": "dummy",
+                        },
+                    ],
+                },
+                package_or_source="package",
+            )
+            providers_manager._discover_hooks()
+            _ = providers_manager._hooks_lazy_dict["dummy"]
+        assert len(self._caplog.records) == 1
+        assert "The connection type 'dummy' is already registered" in self._caplog.records[0].message
+        assert (
+            "different class names: 'airflow.providers.dummy.hooks.dummy.DummyHook'"
+            " and 'airflow.providers.dummy.hooks.dummy.DummyHook2'."
+        ) in self._caplog.records[0].message
+
     def test_hooks(self):
         with pytest.warns(expected_warning=None) as warning_records:
             with self._caplog.at_level(logging.WARNING):