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 18:25:41 UTC
(superset) branch master updated: fix(extensions): log extension-init failures via the logger, not print() (#41304)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new c1787a67aac fix(extensions): log extension-init failures via the logger, not print() (#41304)
c1787a67aac is described below
commit c1787a67aac88325985136d55900b1f26e972fd6
Author: Evan Rusackas <ev...@preset.io>
AuthorDate: Tue Jun 23 11:25:33 2026 -0700
fix(extensions): log extension-init failures via the logger, not print() (#41304)
Co-authored-by: Amin Ghadersohi <am...@gmail.com>
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..0ccd886c054
--- /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() -> MagicMock:
+ 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() -> None:
+ """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