: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): reject cdc sync type on sources without a cdc adapter (#104701)
Daniel RCb432f09c5d02
diff --git a/products/warehouse_sources/backend/presentation/views/external_data_schema.py b/products/warehouse_sources/backend/presentation/views/external_data_schema.pyindex 5442ae40f47a..8ea7769eda00 100644--- a/products/warehouse_sources/backend/presentation/views/external_data_schema.py+++ b/products/warehouse_sources/backend/presentation/views/external_data_schema.py@@ -852,6 +852,11 @@ class ExternalDataSchemaSerializer(UserAccessControlSerializerMixin, serializerssync_type = data.get("sync_type")if sync_type == ExternalDataSchema.SyncType.CDC:+ # The publication step below skips types without an adapter, so accepting one here would+ # save a `cdc` label that nothing can read a change stream for.+ if not source_type_supports_cdc(instance.source.source_type):+ raise ValidationError(f"CDC is not supported for {instance.source.source_type} sources.")+from posthog.models import Teamteam = Team.objects.get(id=self.context["team_id"])diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_schema.py b/products/warehouse_sources/backend/tests/api/test_external_data_schema.pyindex 36c7b36e03f1..aa192ba865ce 100644--- a/products/warehouse_sources/backend/tests/api/test_external_data_schema.py+++ b/products/warehouse_sources/backend/tests/api/test_external_data_schema.py@@ -1223,7 +1223,15 @@ class TestExternalDataSchema(APIBaseTest):schema.refresh_from_db()assert schema.sync_type == ExternalDataSchema.SyncType.FULL_REFRESH- def test_update_schema_to_xmin_rejected_for_non_postgres(self):+ @parameterized.expand(+ [+ ("xmin", "xmin", "postgres"),+ ("cdc", "cdc", "cdc is not supported"),+ ]+ )+ def test_update_schema_replication_sync_type_rejected_for_unsupported_source(+ self, _name: str, sync_type: str, expected_message: str+ ):source = ExternalDataSource.objects.create(team=self.team,source_type=ExternalDataSourceType.MYSQL,@@ -1238,13 +1246,17 @@ class TestExternalDataSchema(APIBaseTest):sync_type_config={"primary_key_columns": ["id"]},)- response = self.client.patch(- f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",- data={"sync_type": "xmin", "primary_key_columns": ["id"]},- )+ with mock.patch(+ "products.warehouse_sources.backend.presentation.views.external_data_schema.is_cdc_enabled_for_team",+ return_value=True,+ ):+ response = self.client.patch(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",+ data={"sync_type": sync_type, "primary_key_columns": ["id"]},+ )- assert response.status_code == status.HTTP_400_BAD_REQUEST- assert "postgres" in str(response.json()).lower()+ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.content+ assert expected_message in str(response.json()).lower()schema.refresh_from_db()assert schema.sync_type == ExternalDataSchema.SyncType.FULL_REFRESH