mirror of
https://github.com/apache/superset.git
synced 2026-08-12 11:11:01 +00:00
fix: close gaps in pkg_resources/sqlalchemy-redshift warning suppression (#41935)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
bab40cf437
commit
8955593b85
@@ -226,6 +226,51 @@ class TestSupersetAppInitializer:
|
||||
assert "secretpass" not in output
|
||||
assert "postgresql://user:***@localhost:5432/db" in output
|
||||
|
||||
@patch("superset.initialization.logger")
|
||||
def test_configure_logging_installs_pkg_resources_filter_before_configurator(
|
||||
self, mock_logger
|
||||
) -> None:
|
||||
"""The pkg_resources warning filter must be installed before
|
||||
LOGGING_CONFIGURATOR.configure_logging() dispatches, so a deployment's
|
||||
custom configurator (which may skip DefaultLoggingConfigurator's own
|
||||
filter) still benefits from it."""
|
||||
import re
|
||||
import warnings
|
||||
|
||||
def has_pkg_resources_filter() -> bool:
|
||||
return any(
|
||||
f[0] == "ignore"
|
||||
and isinstance(f[1], re.Pattern)
|
||||
and f[1].pattern == r"pkg_resources is deprecated as an API"
|
||||
and f[2] is UserWarning
|
||||
and isinstance(f[3], re.Pattern)
|
||||
and f[3].pattern == r"sqlalchemy_redshift(?:\..*)?"
|
||||
for f in warnings.filters
|
||||
)
|
||||
|
||||
seen_during_dispatch = []
|
||||
|
||||
class RecordingConfigurator:
|
||||
def configure_logging(self, app_config, debug_mode):
|
||||
seen_during_dispatch.append(has_pkg_resources_filter())
|
||||
|
||||
mock_app = MagicMock()
|
||||
mock_app.config = {"LOGGING_CONFIGURATOR": RecordingConfigurator()}
|
||||
mock_app.debug = False
|
||||
app_initializer = SupersetAppInitializer(mock_app)
|
||||
|
||||
with warnings.catch_warnings():
|
||||
# Isolate from filters registered by other tests/import side effects.
|
||||
warnings.resetwarnings()
|
||||
assert not has_pkg_resources_filter()
|
||||
|
||||
app_initializer.configure_logging()
|
||||
|
||||
assert seen_during_dispatch == [True], (
|
||||
"pkg_resources filter must already be installed by the time "
|
||||
"LOGGING_CONFIGURATOR.configure_logging() runs"
|
||||
)
|
||||
|
||||
def test_check_and_warn_database_connection_invalid_uri(self) -> None:
|
||||
"""Test that invalid URIs are handled safely without crashing."""
|
||||
mock_app = MagicMock()
|
||||
|
||||
@@ -151,6 +151,24 @@ def test_suppress_third_party_warnings():
|
||||
]
|
||||
assert len(google_filters) >= 1, "Expected google FutureWarning filter"
|
||||
|
||||
# Verify pkg_resources UserWarning filter is installed, scoped to
|
||||
# sqlalchemy_redshift (sqlalchemy-redshift triggers this via a late
|
||||
# import on Redshift-backed connections; see
|
||||
# superset/db_engine_specs/redshift.py for the full rationale). Scoping
|
||||
# by category+module keeps this from also swallowing the same
|
||||
# deprecation message from unrelated dependencies.
|
||||
pkg_resources_filters = [
|
||||
f
|
||||
for f in warnings.filters
|
||||
if f[0] == "ignore"
|
||||
and f[2] is UserWarning
|
||||
and isinstance(f[1], re.Pattern)
|
||||
and f[1].pattern == r"pkg_resources is deprecated as an API"
|
||||
and isinstance(f[3], re.Pattern)
|
||||
and f[3].pattern == r"sqlalchemy_redshift(?:\..*)?"
|
||||
]
|
||||
assert len(pkg_resources_filters) >= 1, "Expected pkg_resources warning filter"
|
||||
|
||||
|
||||
def test_create_event_store_returns_none_when_redis_store_fails():
|
||||
"""EventStore returns None when Redis store creation fails."""
|
||||
|
||||
Reference in New Issue
Block a user