You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/06/23 00:50:37 UTC

(superset) branch fix/extension-init-logging created (now 156e2ed4116)

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

rusackas pushed a change to branch fix/extension-init-logging
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 156e2ed4116 fix(extensions): log extension-init failures via the logger, not print()

This branch includes the following new commits:

     new 156e2ed4116 fix(extensions): log extension-init failures via the logger, not print()

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: fix(extensions): log extension-init failures via the logger, not print()

Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch fix/extension-init-logging
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 156e2ed411694aed3e0ead767397a59e96b1bf11
Author: Amin Ghadersohi <am...@gmail.com>
AuthorDate: Mon Jun 22 17:50:13 2026 -0700

    fix(extensions): log extension-init failures via the logger, not print()
    
    init_extensions caught extension-initialization exceptions and wrote them to
    stdout via print(), bypassing the structured logging pipeline so the failures
    were invisible to operators relying on log aggregation.
    
    Route these through logger.exception (with the failing extension id and a
    traceback) so they reach the configured logging destinations.
    
    Adds a unit test asserting an extension entrypoint failure is logged via
    logger.exception including the extension id.
    
    Co-Authored-By: Claude Fable 5 <no...@anthropic.com>
---
 superset/initialization/__init__.py              | 11 +++--
 tests/unit_tests/test_init_extensions_logging.py | 55 ++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/superset/initialization/__init__.py b/superset/initialization/__init__.py
index 9d77774c57b..65f7977d4d2 100644
--- a/superset/initialization/__init__.py
+++ b/superset/initialization/__init__.py
@@ -610,9 +610,14 @@ class SupersetAppInitializer:  # pylint: disable=too-many-public-methods
                     with extension_context(extension.manifest):
                         eager_import(backend.entrypoint)
 
-                except Exception as ex:  # pylint: disable=broad-except  # noqa: S110
-                    # Surface exceptions during initialization of extensions
-                    print(ex)
+                except Exception:  # pylint: disable=broad-except
+                    # Surface extension-initialization failures through the
+                    # configured logger (with traceback) so they reach log
+                    # aggregation, rather than being written to stdout.
+                    logger.exception(
+                        "Failed to initialize extension '%s'",
+                        extension.manifest.id,
+                    )
 
     def init_app_in_ctx(self) -> None:
         """
diff --git a/tests/unit_tests/test_init_extensions_logging.py b/tests/unit_tests/test_init_extensions_logging.py
new file mode 100644
index 00000000000..1e3a8981198
--- /dev/null
+++ b/tests/unit_tests/test_init_extensions_logging.py
@@ -0,0 +1,55 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Tests for extension-initialization error logging."""
+
+from contextlib import nullcontext
+from unittest.mock import MagicMock, patch
+
+from superset.initialization import SupersetAppInitializer
+
+
+def _extension_that_fails_to_init():
+    extension = MagicMock()
+    extension.backend = None  # skip the in-memory importer branch
+    extension.manifest.id = "acme.broken_extension"
+    extension.manifest.backend.entrypoint = "acme.broken:init"
+    return extension
+
+
+def test_init_extensions_logs_exception_instead_of_printing():
+    """An extension entrypoint failure is routed through logger.exception."""
+    initializer = object.__new__(SupersetAppInitializer)
+    extension = _extension_that_fails_to_init()
+
+    with (
+        patch(
+            "superset.extensions.utils.get_extensions",
+            return_value={"acme.broken_extension": extension},
+        ),
+        patch("superset.extensions.utils.install_in_memory_importer"),
+        patch(
+            "superset.extensions.utils.eager_import",
+            side_effect=RuntimeError("boom"),
+        ),
+        patch("superset.initialization.extension_context", return_value=nullcontext()),
+        patch("superset.initialization.logger") as mock_logger,
+    ):
+        initializer.init_extensions()
+
+    mock_logger.exception.assert_called_once()
+    # The failing extension id is included in the log call args.
+    assert "acme.broken_extension" in mock_logger.exception.call_args.args