: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mixpanel): surface an actionable error for a 400 at validation (#74552)
Tom Owers0f94c0162cac
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.pyindex f404eca62235..6689b5ffce0d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py@@ -199,8 +199,17 @@ def validate_credentials("plan that includes the data export API, and the account must be in good standing. Check your ""Mixpanel plan and billing, then try again.",)+ if response.status_code == 400:+ return (+ False,+ "Mixpanel rejected the request (400). This usually means the project ID isn't valid for the "+ "selected region. Check your project ID and region, then try again.",+ )- return False, f"Mixpanel returned an unexpected status ({response.status_code}) while validating credentials."+ return (+ False,+ "Could not validate your Mixpanel credentials. Check the region, username, secret, and project ID, then try again.",+ )def _check_response(response: requests.Response, url: str, logger: FilteringBoundLogger) -> requests.Response:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.pyindex e01691727fcb..21ae27177384 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py@@ -255,6 +255,7 @@ class TestValidateCredentials:("unauthorized", 401, None, False),("forbidden_at_create", 403, None, True),("forbidden_with_schema", 403, "export", False),+ ("bad_request", 400, None, False),("unexpected", 500, None, False),])@@ -269,6 +270,15 @@ class TestValidateCredentials:else:assert error is not None+ def test_bad_request_points_at_the_project_id(self) -> None:+ # A 400 used to fall through and surface the raw status code, which is not actionable.+ session = MagicMock()+ session.post.return_value = FakeResponse(status_code=400)+ with patch.object(mp, "make_tracked_session", return_value=session):+ ok, error = validate_credentials("us", "user", "secret", "123")+ assert ok is False+ assert error is not None and "project ID" in error+def test_network_error_returns_failure(self) -> None:session = MagicMock()session.post.side_effect = requests.ConnectionError("boom")