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): unblock sync config on disabled CDC schema (#64967)

Daniel RCc5ed4692b540
diff --git a/products/data_warehouse/backend/api/external_data_schema.py b/products/data_warehouse/backend/api/external_data_schema.py
index b018a6a42dc1..57842ba35efa 100644
--- a/products/data_warehouse/backend/api/external_data_schema.py
+++ b/products/data_warehouse/backend/api/external_data_schema.py
@@ -132,6 +132,7 @@ def _reset_cdc_for_full_resnapshot(instance: ExternalDataSchema) -> None:
# Sync frequencies that only CDC schemas may use. Every other sync type floors at 5 minutes.
CDC_ONLY_SYNC_FREQUENCIES = {"1min"}
+NON_CDC_FLOOR_SYNC_FREQUENCY = "5min"
@extend_schema_field(
@@ -702,14 +703,22 @@ class ExternalDataSchemaSerializer(serializers.ModelSerializer):
# frequency the schema will actually end up with — the new value if one is supplied, else
# the existing interval — against the sync type it will end up with. This also catches
# switching a 1-minute CDC schema to a non-CDC type without re-sending the frequency.
+ resulting_sync_type = sync_type if "sync_type" in data else instance.sync_type
resulting_frequency = sync_frequency
if not resulting_frequency and instance.sync_frequency_interval is not None:
resulting_frequency = sync_frequency_interval_to_sync_frequency(instance.sync_frequency_interval)
if resulting_frequency in CDC_ONLY_SYNC_FREQUENCIES and resulting_sync_type != ExternalDataSchema.SyncType.CDC:
- raise ValidationError(
- "A 1-minute sync frequency is only available for CDC schemas. "
- "The fastest frequency for other sync types is 5 minutes."
- )
+ if sync_frequency:
+ # The caller explicitly asked for a CDC-only cadence on a non-CDC schema — a direct
+ # contradiction, so reject it.
+ raise ValidationError(
+ "A 1-minute sync frequency is only available for CDC schemas. "
+ "The fastest frequency for other sync types is 5 minutes."
+ )
+ # Switching a CDC schema to a non-CDC type while it still carries a CDC-only cadence:
+ # clamp to the non-CDC floor instead of dead-ending the switch. The clamp flows through
+ # the sync_frequency handling below.
+ sync_frequency = NON_CDC_FLOOR_SYNC_FREQUENCY
if sync_frequency:
sync_frequency_interval = sync_frequency_to_sync_frequency_interval(sync_frequency)
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.py
index dbbdcd93dd5a..922d77b979c8 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
@@ -1180,9 +1180,10 @@ class TestExternalDataSchema(APIBaseTest):
# Rejected before the interval is persisted.
assert schema.sync_frequency_interval != timedelta(minutes=1)
- def test_update_schema_one_minute_cannot_survive_switch_away_from_cdc(self):
- # Closing the gap where a CDC schema on a 1-minute schedule is switched to a non-CDC sync
- # type without re-sending sync_frequency — the existing 1-minute interval must be rejected.
+ def test_update_schema_one_minute_clamps_on_switch_away_from_cdc(self):
+ # A CDC schema on a 1-minute schedule switched to a non-CDC sync type without re-sending
+ # sync_frequency would otherwise dead-end (1-minute is CDC-only). Instead of rejecting the
+ # switch, clamp the inherited cadence to the non-CDC floor so the switch goes through.
source = ExternalDataSource.objects.create(
team=self.team,
source_type=ExternalDataSourceType.POSTGRES,
@@ -1199,16 +1200,23 @@ class TestExternalDataSchema(APIBaseTest):
sync_frequency_interval=timedelta(minutes=1),
)
- response = self.client.patch(
- f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",
- data={"sync_type": "incremental"},
- )
+ with (
+ mock.patch(
+ "products.data_warehouse.backend.api.external_data_schema.external_data_workflow_exists",
+ return_value=False,
+ ),
+ mock.patch("products.data_warehouse.backend.api.external_data_schema.sync_external_data_job_workflow"),
+ mock.patch("products.data_warehouse.backend.api.external_data_schema.sync_cdc_extraction_schedule"),
+ ):
+ response = self.client.patch(
+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",
+ data={"sync_type": "full_refresh"},
+ )
- assert response.status_code == 400, response.content
- assert "cdc" in str(response.json()).lower()
+ assert response.status_code == 200, response.content
schema.refresh_from_db()
- assert schema.sync_frequency_interval == timedelta(minutes=1)
- assert schema.sync_type == ExternalDataSchema.SyncType.CDC
+ assert schema.sync_frequency_interval == timedelta(minutes=5)
+ assert schema.sync_type == ExternalDataSchema.SyncType.FULL_REFRESH
def test_update_schema_frequency_on_disabled_schema_does_not_touch_missing_schedule(self):
# A disabled / never-activated schema has no Temporal schedule. Changing its sync frequency
diff --git a/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx b/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx
index 64bcfa0c6f70..b405f6d0df21 100644
--- a/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx
+++ b/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx
@@ -741,10 +741,7 @@ function ScheduleSection({
</span>
<LemonSelect
fullWidth
- disabledReason={
- accessDisabledReason ??
- (!schema.should_sync ? 'Enable syncing to set frequency' : undefined)
- }
+ disabledReason={accessDisabledReason}
value={draftFrequency}
onChange={(value) => setDraftFrequency(value as DataWarehouseSyncInterval)}
options={frequencyOptions}