: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): stop capturing expected connect errors on schema probe (#73742)
Tom Owersdf11be2a629d
diff --git a/products/warehouse_sources/backend/presentation/views/external_data_schema.py b/products/warehouse_sources/backend/presentation/views/external_data_schema.pyindex eb3c376bea5b..ec3f1c68b57a 100644--- a/products/warehouse_sources/backend/presentation/views/external_data_schema.py+++ b/products/warehouse_sources/backend/presentation/views/external_data_schema.py@@ -1625,7 +1625,14 @@ class ExternalDataSchemaViewset(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):config, self.team_id, names=[instance.name], api_version=effective_api_version)except Exception as e:- capture_exception(e)+ # `validate_credentials` above just probed the same connection successfully, so a+ # failure here that the source itself classifies as non-retryable (e.g. a connect-time+ # timeout, which usually means an unreachable host or unconfigured firewall) is an+ # expected customer/upstream condition, not a bug — don't flood error tracking with it.+ # Mirrors `refresh_schemas`'s `_classify_refresh_schemas_error`.+ error_text = str(e)+ if not any(pattern and pattern in error_text for pattern in new_source.get_non_retryable_errors()):+ capture_exception(e)return Response(status=status.HTTP_400_BAD_REQUEST,data={"message": str(e)},diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_schema.py b/products/warehouse_sources/backend/tests/api/test_external_data_schema.pyindex 54f283931b28..0a396211f428 100644--- a/products/warehouse_sources/backend/tests/api/test_external_data_schema.py+++ b/products/warehouse_sources/backend/tests/api/test_external_data_schema.py@@ -122,6 +122,45 @@ class TestExternalDataSchema(APIBaseTest):"detected_primary_keys": None,}+ @parameterized.expand(+ [+ ("expected_source_error", Exception("Invalid API Key provided"), False),+ ("unclassified_error", RuntimeError("schema parser exploded"), True),+ ]+ )+ @mock.patch("products.warehouse_sources.backend.presentation.views.external_data_schema.capture_exception")+ def test_incremental_fields_capture_depends_on_non_retryable_classification(+ self, _name, raised_exception, should_capture, mock_capture_exception+ ):+ # `validate_credentials` above this call already probed the same connection successfully, so+ # a failure the source itself classifies as non-retryable (e.g. bad credentials, an+ # unreachable host) is an expected customer/upstream condition and must not flood error+ # tracking - mirrors `refresh_schemas`'s equivalent classification.+ source = ExternalDataSource.objects.create(+ team=self.team,+ source_type=ExternalDataSourceType.STRIPE,+ job_inputs={"auth_method": {"selection": "api_key", "stripe_secret_key": "123"}},+ )+ schema = ExternalDataSchema.objects.create(+ name="BalanceTransaction",+ team=self.team,+ source=source,+ should_sync=True,+ status=ExternalDataSchema.Status.COMPLETED,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ )+ with (+ mock.patch.object(StripeSource, "validate_credentials", return_value=(True, None)),+ mock.patch.object(StripeSource, "get_schemas", side_effect=raised_exception),+ ):+ response = self.client.post(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}/incremental_fields",+ )++ assert response.status_code == 400+ assert response.json()["message"] == str(raised_exception)+ assert mock_capture_exception.called is should_capture+def test_incremental_fields_probe_uses_schema_pin_over_source_pin(self):# A schema-level api_version override must win over the source pin in capability probes,# matching sync-time precedence — consolidating probe callers to the source pin would