: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): search external data sources by type and prefix (#64198)
Marcus Hofc1eb8375db87
diff --git a/products/data_warehouse/backend/api/external_data_source.py b/products/data_warehouse/backend/api/external_data_source.pyindex 9c9c2e92c804..a1baf698727f 100644--- a/products/data_warehouse/backend/api/external_data_source.py+++ b/products/data_warehouse/backend/api/external_data_source.py@@ -1217,7 +1217,10 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixiqueryset = ExternalDataSource.objects.all()serializer_class = ExternalDataSourceSerializersfilter_backends = [filters.SearchFilter]- search_fields = ["source_id"]+ # `source_id` is an opaque internal connection UUID — useless to search by. Callers+ # (the in-app sources list, the MCP tool) narrow by what they can actually see: the+ # source type ("Stripe", "Postgres") and the HogQL table prefix.+ search_fields = ["source_type", "prefix"]ordering = "-created_at"def get_serializer_class(self) -> type[serializers.Serializer]:diff --git a/products/data_warehouse/backend/api/test/test_external_data_source.py b/products/data_warehouse/backend/api/test/test_external_data_source.pyindex 213b9a7a21f6..e928549ab309 100644--- a/products/data_warehouse/backend/api/test/test_external_data_source.py+++ b/products/data_warehouse/backend/api/test/test_external_data_source.py@@ -1250,6 +1250,45 @@ class TestExternalDataSource(APIBaseTest):self.assertEqual(response.status_code, 200)self.assertEqual(len(payload["results"]), 2)+ def _create_searchable_source(self, source_type: str, prefix: str) -> ExternalDataSource:+ return 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=source_type,+ created_by=self.user,+ prefix=prefix,+ )++ # Sentinel resolved to a freshly-created source's opaque internal source_id at runtime,+ # to assert that searching by it no longer matches.+ SEARCH_BY_INTERNAL_SOURCE_ID = object()++ @parameterized.expand(+ [+ ("by_source_type", "Stripe", ["prod_payments"]),+ ("by_source_type_other", "Postgres", ["analytics"]),+ ("by_prefix_partial", "prod_", ["prod_payments"]),+ ("by_prefix_full", "analytics", ["analytics"]),+ ("no_match", "nonexistent", []),+ ("internal_source_id_is_not_searchable", SEARCH_BY_INTERNAL_SOURCE_ID, []),+ ]+ )+ def test_list_external_data_source_search(self, _name, term, expected_prefixes):+ sources = {+ "prod_payments": self._create_searchable_source(source_type="Stripe", prefix="prod_payments"),+ "analytics": self._create_searchable_source(source_type="Postgres", prefix="analytics"),+ }+ if term is self.SEARCH_BY_INTERNAL_SOURCE_ID:+ term = sources["analytics"].source_id++ response = self.client.get(f"/api/environments/{self.team.pk}/external_data_sources/?search={term}")++ assert response.status_code == 200+ returned_prefixes = sorted(r["prefix"] for r in response.json()["results"])+ assert returned_prefixes == sorted(expected_prefixes)+def test_connections_returns_lightweight_direct_connection_options(self):source = ExternalDataSource.objects.create(team_id=self.team.pk,