: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): shrink new-source wizard payload and gzip it (#70804)
Daniel RC5686468e8e3a
diff --git a/posthog/settings/web.py b/posthog/settings/web.pyindex 456513dd9eed..6e6152944b46 100644--- a/posthog/settings/web.py+++ b/posthog/settings/web.py@@ -840,6 +840,9 @@ GZIP_RESPONSE_ALLOW_LIST = get_list("^/api/organizations/@current/plugins/?$","^api/(environments|projects)/@current/feature_flags/my_flags/?$","^/?api/(environments|projects)/\\d+/query/?$",+ # Deploy-static source catalog (no user input or secrets reflected): several+ # hundred KB of JSON that compresses ~7x.+ "^/?api/(environments|projects)/(\\d+|@current)/external_data_sources/wizard/?$","^/?api/instance_status/?$","^/array/.*$",]diff --git a/products/data_warehouse/backend/presentation/views/external_data_source.py b/products/data_warehouse/backend/presentation/views/external_data_source.pyindex 680fdb3da997..3cf597f02d75 100644--- a/products/data_warehouse/backend/presentation/views/external_data_source.py+++ b/products/data_warehouse/backend/presentation/views/external_data_source.py@@ -4161,7 +4161,9 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi)@action(methods=["GET"], detail=False)def wizard(self, request: Request, *arg: Any, **kwargs: Any):- configs = build_source_configs()+ # The documented-tables catalog is only consumed by the posthog.com docs build (via the+ # public endpoint) — skipping it here cuts ~40% off an already >1 MB response.+ configs = build_source_configs(include_tables=False)requested = request.query_params.get("source_type")if requested:diff --git a/products/data_warehouse/backend/presentation/views/public_source_configs.py b/products/data_warehouse/backend/presentation/views/public_source_configs.pyindex c6abc74cec6e..f2844cda2a5d 100644--- a/products/data_warehouse/backend/presentation/views/public_source_configs.py+++ b/products/data_warehouse/backend/presentation/views/public_source_configs.py@@ -1,3 +1,5 @@+import functools+import structlogfrom drf_spectacular.utils import extend_schemafrom rest_framework import permissions, status, viewsets@@ -11,12 +13,18 @@ from products.warehouse_sources.backend.facade.source_management import SourceRelogger = structlog.get_logger(__name__)-def build_source_configs() -> dict[str, dict]:+def build_source_configs(*, include_tables: bool = True) -> dict[str, dict]:"""Build the source-config catalog returned by both the public endpoint and the wizard.- Each entry is the source's ``SourceConfig`` augmented with ``supportsColumnSelection`` and a- credential-free ``tables`` catalog (empty for SQL/file sources with user-defined schemas). Kept- in one place so the two endpoints can never drift (see ``test_matches_wizard_response``).+ Each entry is the source's ``SourceConfig`` augmented with ``supportsColumnSelection`` and,+ when ``include_tables`` is set, a credential-free ``tables`` catalog (empty for SQL/file+ sources with user-defined schemas). ``tables`` exists for the posthog.com docs build; the+ in-app wizard skips it because nothing in the app reads it and it is ~40% of the payload.+ Kept in one place so the two endpoints can never drift (see ``test_matches_wizard_response``).++ The catalog is deploy-static (it only changes when source code ships), so the result is+ memoized per process — callers must treat it as read-only."""sources = SourceRegistry.get_all_sources()@@ -24,12 +32,13 @@ def build_source_configs() -> dict[str, dict]:for source_type, source in sources.items():config = source.get_source_config.model_dump()config["supportsColumnSelection"] = bool(source.supports_column_selection)- # Per-source guard: a single misbehaving source must never break the whole catalog.- try:- config["tables"] = source.get_documented_tables()- except Exception:- logger.exception("build_source_configs: get_documented_tables failed", source_type=str(source_type))- config["tables"] = []+ if include_tables:+ # Per-source guard: a single misbehaving source must never break the whole catalog.+ try:+ config["tables"] = source.get_documented_tables()+ except Exception:+ logger.exception("build_source_configs: get_documented_tables failed", source_type=str(source_type))+ config["tables"] = []results[str(source_type)] = configreturn resultsdiff --git a/products/data_warehouse/backend/tests/api/test_public_source_configs.py b/products/data_warehouse/backend/tests/api/test_public_source_configs.pyindex 6571077b7d2e..bdb0cafc48e4 100644--- a/products/data_warehouse/backend/tests/api/test_public_source_configs.py+++ b/products/data_warehouse/backend/tests/api/test_public_source_configs.py@@ -19,14 +19,22 @@ class TestPublicSourceConfigs(APIBaseTest):assert "fields" in first_configdef test_matches_wizard_response(self):- """Public endpoint should return the same data as the authenticated /wizard endpoint."""+ """Public endpoint returns the same data as the authenticated /wizard endpoint, plus the+ docs-only `tables` catalog the wizard deliberately omits to keep its payload small."""response = self.client.get("/api/public_source_configs/")assert response.status_code == status.HTTP_200_OKwizard_response = self.client.get("/api/environments/@current/external_data_sources/wizard/")assert wizard_response.status_code == status.HTTP_200_OK- assert response.json() == wizard_response.json()+ wizard_data = wizard_response.json()+ assert not any("tables" in config for config in wizard_data.values())++ public_without_tables = {+ source_type: {k: v for k, v in config.items() if k != "tables"}+ for source_type, config in response.json().items()+ }+ assert public_without_tables == wizard_datadef test_accessible_without_authentication(self):self.client.logout()