: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(warehouse-sources): clearer error when a source has no schema discovery (#87672)
Tom Owers8048f89a2772
diff --git a/products/warehouse_sources/backend/presentation/views/external_data_source.py b/products/warehouse_sources/backend/presentation/views/external_data_source.pyindex 7bafa2852a6f..877a142a0fa7 100644--- a/products/warehouse_sources/backend/presentation/views/external_data_source.py+++ b/products/warehouse_sources/backend/presentation/views/external_data_source.py@@ -183,6 +183,15 @@ INVALID_CREDENTIALS_FALLBACK_MESSAGE = ()+def _source_unavailable_message(source_type: str) -> str:+ # A source with no schema discovery is an unreleased scaffold the UI normally hides. Tell the+ # user it isn't ready rather than exposing the internal "schema discovery" wording.+ return (+ f"The {source_type} source isn't available to connect yet. "+ "Choose a different source, or contact support if you were expecting it."+ )++def _canonical_legacy_managed_warehouse_source(queryset: QuerySet[ExternalDataSource],) -> ExternalDataSource | None:@@ -2478,9 +2487,10 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi# Roll back the row just created so a caller can't accumulate orphaned sources, and return# a clean 400 instead of the uncaught 500 this would otherwise raise. Mirrors `setup`.new_source_model.delete()+ # nosemgrep: api-response-must-match-schema -- conventional error message, not a schema-bound payloadreturn Response(status=status.HTTP_400_BAD_REQUEST,- data={"message": f"Source type '{source_type}' does not support schema discovery."},+ data={"message": _source_unavailable_message(source_type)},)except Exception as e:# `get_schemas` opens its own connection, so credentials validated above can still fail@@ -3379,9 +3389,10 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixiexcept NotImplementedError:# Source doesn't implement schema discovery (e.g. an unreleased source), so there are# no tables to list — a caller mistake, not a server error worth capturing. Mirrors `setup`.+ # nosemgrep: api-response-must-match-schema -- conventional error message, not a schema-bound payloadreturn Response(status=status.HTTP_400_BAD_REQUEST,- data={"message": f"Source type '{source_type}' does not support schema discovery."},+ data={"message": _source_unavailable_message(source_type)},)except Exception as e:error_message, is_expected_source_error = _classify_refresh_schemas_error(source, e)@@ -3494,9 +3505,10 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixiexcept NotImplementedError:# Source doesn't implement schema discovery (e.g. an unreleased source) so it can't be# set up via this one-shot flow — a caller mistake, not a server error worth capturing.+ # nosemgrep: api-response-must-match-schema -- conventional error message, not a schema-bound payloadreturn Response(status=status.HTTP_400_BAD_REQUEST,- data={"message": f"Source type '{source_type}' does not support one-shot setup."},+ data={"message": _source_unavailable_message(source_type)},)except Exception as e:# Credentials validated above can still fail here — `get_schemas` opens its owndiff --git a/products/warehouse_sources/backend/tests/api/test_external_data_source.py b/products/warehouse_sources/backend/tests/api/test_external_data_source.pyindex ea9345d5cf28..d8ff2a90adca 100644--- a/products/warehouse_sources/backend/tests/api/test_external_data_source.py+++ b/products/warehouse_sources/backend/tests/api/test_external_data_source.py@@ -5143,7 +5143,10 @@ class TestExternalDataSource(APIBaseTest):)assert response.status_code == 400- assert response.json()["message"] == "Source type 'AmazonS3' does not support schema discovery."+ assert response.json()["message"] == (+ "The AmazonS3 source isn't available to connect yet. "+ "Choose a different source, or contact support if you were expecting it."+ )mock_capture_exception.assert_not_called()def test_database_schema_stripe_surfaces_per_endpoint_permission_errors(self):@@ -11744,7 +11747,7 @@ class TestExternalDataSourceSetup(APIBaseTest):data={"source_type": "AmazonS3", "prefix": "s3_setup_test", "payload": {}},)assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()- assert "does not support one-shot setup" in response.json()["message"]+ assert "isn't available to connect yet" in response.json()["message"]mock_capture_exception.assert_not_called()assert not ExternalDataSource.objects.filter(team=self.team).exists()@@ -11785,7 +11788,7 @@ class TestExternalDataSourceSetup(APIBaseTest):data={"source_type": "AmazonS3", "prefix": "s3_create_test", "payload": {}},)assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()- assert "does not support schema discovery" in response.json()["message"]+ assert "isn't available to connect yet" in response.json()["message"]assert not ExternalDataSource.objects.filter(team=self.team).exists()def _create_stripe_webhook_template(self):