: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(data-warehouse): skip error capture for expected schema-discovery errors (#66389)
Tom Owers599788c35a2b
diff --git a/products/data_warehouse/backend/presentation/views/external_data_source.py b/products/data_warehouse/backend/presentation/views/external_data_source.pyindex 55e7e2d54170..9e73060a6620 100644--- a/products/data_warehouse/backend/presentation/views/external_data_source.py+++ b/products/data_warehouse/backend/presentation/views/external_data_source.py@@ -2459,7 +2459,9 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixitry:schemas = source.get_schemas(source_config, self.team_id)except Exception as e:- capture_exception(e, {"source_type": source_type, "team_id": self.team_id})+ _, is_expected_source_error = _classify_refresh_schemas_error(source, e)+ if not is_expected_source_error:+ capture_exception(e, {"source_type": source_type, "team_id": self.team_id})return Response(status=status.HTTP_400_BAD_REQUEST,data={"message": str(e)},diff --git a/products/data_warehouse/backend/tests/api/test_external_data_source.py b/products/data_warehouse/backend/tests/api/test_external_data_source.pyindex 9561ed75dd42..449f9843c349 100644--- a/products/data_warehouse/backend/tests/api/test_external_data_source.py+++ b/products/data_warehouse/backend/tests/api/test_external_data_source.py@@ -3996,6 +3996,49 @@ class TestExternalDataSource(APIBaseTest):assert response.status_code == 400assert "Stripe credentials lack permissions for Account, Invoice" in response.json()["message"]+ @parameterized.expand(+ [+ ("expected_source_error", False),+ ("unexpected_source_error", True),+ ]+ )+ @patch("products.data_warehouse.backend.presentation.views.external_data_source.capture_exception")+ @patch("products.data_warehouse.backend.presentation.views.external_data_source.SourceRegistry.get_source")+ def test_database_schema_captures_only_unexpected_source_errors(+ self, _name, expect_capture, mock_get_source, mock_capture_exception+ ):+ from products.warehouse_sources.backend.temporal.data_imports.sources.bigquery.bigquery import (+ BIGQUERY_DATASET_NOT_FOUND_ERROR,+ BigQueryDatasetNotFoundError,+ )+ from products.warehouse_sources.backend.temporal.data_imports.sources.bigquery.source import BigQuerySource++ error: Exception = (+ RuntimeError("schema discovery exploded")+ if expect_capture+ else BigQueryDatasetNotFoundError(BIGQUERY_DATASET_NOT_FOUND_ERROR)+ )+ source = BigQuerySource()+ mock_get_source.return_value = source++ with (+ patch.object(source, "validate_config", return_value=(True, [])),+ patch.object(source, "parse_config", return_value=None),+ patch.object(source, "validate_credentials", return_value=(True, None)),+ patch.object(source, "get_schemas", side_effect=error),+ ):+ response = self.client.post(+ f"/api/environments/{self.team.pk}/external_data_sources/database_schema/",+ data={"source_type": "BigQuery"},+ )++ assert response.status_code == 400+ assert response.json()["message"] == str(error)+ if expect_capture:+ mock_capture_exception.assert_called_once_with(error, {"source_type": "BigQuery", "team_id": self.team.pk})+ else:+ mock_capture_exception.assert_not_called()+def test_database_schema_stripe_surfaces_per_endpoint_permission_errors(self):"""Schema-selection step calls get_endpoint_permissions and merges the per-endpointresult into each schema row so the UI can disable tables the credentials can't reach."""