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): return a clear error for unknown source types when validating schemas (#68098)

Tom Owers3009514e6aab
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 df7f1588e55c..1946e7a33245 100644
--- a/products/data_warehouse/backend/presentation/views/external_data_source.py
+++ b/products/data_warehouse/backend/presentation/views/external_data_source.py
@@ -2628,7 +2628,13 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi
if secret_ref_response is not None:
return secret_ref_response
- source_type_model = ExternalDataSourceType(source_type)
+ try:
+ source_type_model = ExternalDataSourceType(source_type)
+ except ValueError:
+ return Response(
+ status=status.HTTP_400_BAD_REQUEST,
+ data={"message": f"Unknown source_type '{source_type}'"},
+ )
source = SourceRegistry.get_source(source_type_model)
is_valid, errors = source.validate_config(request.data)
if not is_valid:
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 66dfa72a2207..2d4de35137ea 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
@@ -3949,6 +3949,15 @@ class TestExternalDataSource(APIBaseTest):
postgres_connection.close()
+ def test_database_schema_unknown_source_type(self):
+ response = self.client.post(
+ f"/api/environments/{self.team.pk}/external_data_sources/database_schema/",
+ data={"source_type": "GoogleAds-"},
+ )
+
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+ assert response.json()["message"] == "Unknown source_type 'GoogleAds-'"
+
def test_database_schema_stripe_credentials(self):
with (
patch(