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(data-warehouse): don't capture expected errors on sync defaults (#72139)

Tom Owers06bb63bde26b
diff --git a/products/data_warehouse/backend/presentation/views/external_data_source.py b/products/data_warehouse/backend/presentation/views/external_data_source.py
index cac877308074..e92f2e0ef3f8 100644
--- a/products/data_warehouse/backend/presentation/views/external_data_source.py
+++ b/products/data_warehouse/backend/presentation/views/external_data_source.py
@@ -4766,12 +4766,18 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi
failures: dict[str, tuple[str, str]] = {}
names = [source_schemas_by_id[schema_update["id"]].name for schema_update in needing_defaults]
+ source_impl: AnySource | None = None
try:
source_impl = SourceRegistry.get_source(ExternalDataSourceType(source.source_type))
config = source_impl.parse_config(source.job_inputs)
discovered = source_impl.get_schemas(config, self.team_id, names=names)
except Exception as e:
- capture_exception(e)
+ # Discovery connects to the customer's source, so an expected user/upstream failure
+ # (bad credentials, unreachable host) is theirs to fix and is already reported back to
+ # them below — don't capture it as error-tracking noise. Mirrors `refresh_schemas`.
+ _, is_expected_source_error = _classify_refresh_schemas_error(source_impl, e)
+ if not is_expected_source_error:
+ capture_exception(e)
reason = "could not read the source to pick default sync settings; check the source credentials"
for schema_update in needing_defaults:
schema = source_schemas_by_id[schema_update["id"]]
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.py
index 0a9e407a63e9..8688db8771dd 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
@@ -1342,6 +1342,68 @@ class TestExternalDataSource(APIBaseTest):
assert configured_schema.should_sync is True
assert mock_unpause.call_count == 1
+ @parameterized.expand(
+ [
+ # A bad-credentials rejection from the customer's database is theirs to fix and is
+ # already reported back in the response, so it must not be captured as error-tracking noise.
+ (
+ "expected_credential_error",
+ psycopg.OperationalError(
+ 'connection failed: FATAL: password authentication failed for user "postgres"'
+ ),
+ False,
+ ),
+ # An unexpected error still points at a bug in our discovery code, so keep capturing it.
+ ("unexpected_error", ValueError("unexpected discovery failure"), True),
+ ]
+ )
+ @patch(
+ "products.data_warehouse.backend.presentation.views.external_data_schema.external_data_workflow_exists",
+ return_value=False,
+ )
+ @patch("products.data_warehouse.backend.presentation.views.external_data_source.capture_exception")
+ def test_bulk_update_schemas_apply_sync_defaults_skips_capture_for_expected_errors(
+ self, _name, raised_exception, should_capture, mock_capture_exception, _mock_workflow_exists
+ ):
+ source = ExternalDataSource.objects.create(
+ team_id=self.team.pk,
+ source_id=str(uuid.uuid4()),
+ connection_id=str(uuid.uuid4()),
+ destination_id=str(uuid.uuid4()),
+ source_type="Postgres",
+ created_by=self.user,
+ prefix="pg",
+ job_inputs={
+ "host": "localhost",
+ "port": 5432,
+ "database": "app",
+ "user": "user",
+ "password": "pass",
+ "schema": "public",
+ },
+ )
+ schema = ExternalDataSchema.objects.create(
+ name="Customer", team_id=self.team.pk, source=source, should_sync=False, sync_type=None
+ )
+
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.postgres.source.PostgresSource.get_schemas",
+ side_effect=raised_exception,
+ ):
+ response = self.client.patch(
+ f"/api/environments/{self.team.pk}/external_data_sources/{source.id}/bulk_update_schemas",
+ data={"schemas": [{"id": str(schema.id), "should_sync": True, "apply_sync_defaults": True}]},
+ format="json",
+ )
+
+ # Discovery failed, so the schema is reported back either way and stays unconfigured.
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+ assert "could not read the source" in response.json()["detail"]
+ schema.refresh_from_db()
+ assert schema.should_sync is False
+
+ assert mock_capture_exception.called is should_capture
+
@patch(
"products.data_warehouse.backend.presentation.views.external_data_schema.external_data_workflow_exists",
return_value=True,