Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(metabase): hide raw connection errors from session sign-in (#124630)

Tom Owers49b6194dec8c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/metabase.py b/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/metabase.py
index 871e97e70b7c..ccfb4713b93e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/metabase.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/metabase.py
@@ -261,7 +261,11 @@ def validate_credentials(
try:
headers = _resolve_auth_headers(base_url, auth, structlog.get_logger())
- except (MetabaseAuthError, MetabaseRetryableError) as e:
+ except MetabaseRetryableError as e:
+ if isinstance(e.__cause__, requests.exceptions.RequestException):
+ return False, _connection_error_message(e.__cause__)
+ return False, str(e)
+ except MetabaseAuthError as e:
return False, str(e)
session = make_tracked_session(redact_values=_redact_values_for_data_requests(auth, headers))
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/tests/test_metabase.py b/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/tests/test_metabase.py
index 3d574688c9db..42ab8920ab63 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/tests/test_metabase.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/tests/test_metabase.py
@@ -153,13 +153,14 @@ class TestValidateCredentials:
assert valid is False
assert msg == "Invalid Metabase host"
- def test_connection_error_does_not_leak_raw_exception(self):
+ @pytest.mark.parametrize("auth", [_api_key_auth(), _session_auth()], ids=["api_key", "session"])
+ def test_connection_error_does_not_leak_raw_exception(self, auth):
# requests connection errors embed the customer's host/IP and give the user nothing to act
# on. The (fictional-range) IP and the raw blob must never reach the user; a friendly,
# actionable message must.
raw = "HTTPSConnectionPool(host='203.0.113.10', port=3000): Max retries exceeded"
with scripted_network(always(ConnectionResetError(raw))):
- valid, msg = validate_credentials("https://x.metabaseapp.com", _api_key_auth())
+ valid, msg = validate_credentials("https://x.metabaseapp.com", auth)
assert valid is False
assert msg is not None
assert "203.0.113.10" not in msg