: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): gate cdc_available on source-level cdc_enabled (#58044)
Daniel RCcab38b1fc008
diff --git a/products/data_warehouse/backend/api/external_data_schema.py b/products/data_warehouse/backend/api/external_data_schema.pyindex 08ceb7f3c10d..910a557ae197 100644--- a/products/data_warehouse/backend/api/external_data_schema.py+++ b/products/data_warehouse/backend/api/external_data_schema.py@@ -716,11 +716,14 @@ class ExternalDataSchemaViewset(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):schema = schemas[0]+ source_cdc_enabled = bool(source.job_inputs.get("cdc_enabled"))+ cdc_available = schema.supports_cdc if is_cdc_enabled_for_team(self.team) and source_cdc_enabled else None+data = {"incremental_fields": schema.incremental_fields,"incremental_available": schema.supports_incremental,"append_available": schema.supports_append,- "cdc_available": schema.supports_cdc if is_cdc_enabled_for_team(self.team) else None,+ "cdc_available": cdc_available,"full_refresh_available": True,"supports_webhooks": schema.supports_webhooks,"available_columns": [diff --git a/products/data_warehouse/backend/api/test/test_external_data_schema.py b/products/data_warehouse/backend/api/test/test_external_data_schema.pyindex 0d025e493f3e..0c3f449f606e 100644--- a/products/data_warehouse/backend/api/test/test_external_data_schema.py+++ b/products/data_warehouse/backend/api/test/test_external_data_schema.py@@ -219,6 +219,71 @@ class TestExternalDataSchema(APIBaseTest):"detected_primary_keys": ["id"],}+ @parameterized.expand(+ [+ # (test name, source_cdc_enabled, team_ff_enabled, expected_cdc_available)+ ("source_enabled_team_enabled", True, True, True),+ ("source_enabled_team_disabled", True, False, None),+ ("source_disabled_team_enabled", False, True, None),+ ("source_disabled_team_disabled", False, False, None),+ ]+ )+ def test_incremental_fields_cdc_available_gating(+ self, _name: str, source_cdc_enabled: bool, team_ff_enabled: bool, expected_cdc_available+ ):+ from posthog.temporal.data_imports.sources.postgres.source import PostgresSource++ job_inputs = {+ "host": "localhost",+ "port": 5432,+ "database": "postgres",+ "user": "postgres",+ "password": "postgres",+ "schema": "public",+ "ssh_tunnel_enabled": False,+ }+ if source_cdc_enabled:+ job_inputs["cdc_enabled"] = True++ source = ExternalDataSource.objects.create(+ team=self.team,+ source_type="Postgres",+ job_inputs=job_inputs,+ )+ schema = ExternalDataSchema.objects.create(+ name="some_table",+ team=self.team,+ source=source,+ should_sync=True,+ status=ExternalDataSchema.Status.COMPLETED,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ )++ fake_schema = SourceSchema(+ name="some_table",+ supports_incremental=False,+ supports_append=False,+ supports_cdc=True,+ incremental_fields=[],+ columns=[("id", "integer", False)],+ detected_primary_keys=["id"],+ )++ with (+ mock.patch.object(PostgresSource, "validate_credentials", return_value=(True, None)),+ mock.patch.object(PostgresSource, "get_schemas", return_value=[fake_schema]),+ mock.patch(+ "products.data_warehouse.backend.api.external_data_schema.is_cdc_enabled_for_team",+ return_value=team_ff_enabled,+ ),+ ):+ response = self.client.post(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}/incremental_fields",+ )++ assert response.status_code == status.HTTP_200_OK+ assert response.json()["cdc_available"] is expected_cdc_available+def test_update_schema_change_sync_type(self):source = ExternalDataSource.objects.create(team=self.team,