: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): pause CDC schedule on non-retryable errors (#71453)
estefaniaf05b34669f01
diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.pyindex 348739c9a085..962110bd339b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py@@ -1189,6 +1189,19 @@ class CDCExtractActivity:except Exception:schema_log.warning("failed_to_unpause_schema_schedule", schema_id=str(schema.id), exc_info=True)+ def _pause_cdc_extraction_schedule(self) -> None:+ """Pause the source's CDC extraction schedule after a non-retryable failure (best-effort)."""+ assert self.source is not None+ source_id = str(self.source.id)+ try:+ # Deferred: data_load.service participates in the CDC schedule<->workflow import cycle.+ from products.data_warehouse.backend.facade.api import pause_cdc_extraction_schedule++ pause_cdc_extraction_schedule(source_id)+ self.log.warning("cdc_extraction_schedule_paused_non_retryable", source_id=source_id)+ except Exception:+ self.log.warning("cdc_pause_schedule_failed", source_id=source_id, exc_info=True)+def _handle_no_changes(self, truncated_tables: list[str]) -> None:"""Early-return path: no DML events were read."""if truncated_tables:@@ -1381,6 +1394,10 @@ class CDCExtractActivity:if marked_broken:assert self.source is not Nonemark_cdc_broken(self.source, info.category.value, friendly)+ elif not info.retryable and self.source is not None:+ # A non-retryable error re-fails every scheduled run, so pause the schedule instead of+ # looping it. No cdc_broken marker: the slot is intact, so it stays Repair-CDC-ineligible.+ self._pause_cdc_extraction_schedule()for schema in self.cdc_schemas:if not marked_broken:schema.status = ExternalDataSchema.Status.FAILEDdiff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.pyindex fcb74026ea98..6c909d137812 100644--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py@@ -951,8 +951,10 @@ class TestCDCExtractActivity:@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.ExternalDataSource")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.ExternalDataJob")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.close_old_connections")+ @patch.object(CDCExtractActivity, "_pause_cdc_extraction_schedule")def test_unmergeable_schema_fails_non_retryably(self,+ _mock_pause_schedule,mock_close_conns,MockJob,MockSourceModel,@@ -1806,8 +1808,10 @@ class TestErrorClassification:@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.ExternalDataSource")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.ExternalDataJob")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.close_old_connections")+ @patch.object(CDCExtractActivity, "_pause_cdc_extraction_schedule")def test_non_retryable_error_raises_nonretryable_and_captures(self,+ _mock_pause_schedule,mock_close_conns,MockJob,MockSourceModel,@@ -1878,12 +1882,14 @@ class TestErrorClassification:@patch.object(CDCExtractActivity, "_get_cdc_schemas")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.ExternalDataSource")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.close_old_connections")+ @patch.object(CDCExtractActivity, "_pause_cdc_extraction_schedule")def test_missing_slot_or_publication_marks_cdc_broken(self,_name,exc_cls,exc_message,expected_reason,+ mock_pause,mock_close_conns,MockSourceModel,mock_get_schemas,@@ -1893,9 +1899,8 @@ class TestErrorClassification:mock_get_machine_id,mock_mark_broken,):- # A missing slot/publication is non-retryable and must trip mark_cdc_broken (pause + persist- # the broken marker) so the schedule stops firing against a resource that no longer exists.- # A transient auth failure, equally non-retryable, must NOT — it could recover.+ # Slot/publication errors mark_cdc_broken (pause + broken marker); an auth failure has an+ # intact slot, so it pauses the schedule directly without the broken marker.source = _make_source()MockSourceModel.objects.get.return_value = sourceschema = _make_schema("users", cdc_mode="streaming", source=source)@@ -1919,10 +1924,12 @@ class TestErrorClassification:if expected_reason is None:mock_mark_broken.assert_not_called()+ mock_pause.assert_called_once()else:mock_mark_broken.assert_called_once()assert mock_mark_broken.call_args.args[0] is sourceassert mock_mark_broken.call_args.args[1] == expected_reason+ mock_pause.assert_not_called()@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.mark_cdc_broken")@patch(@@ -1998,8 +2005,10 @@ class TestErrorClassification:@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.ExternalDataSource")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.ExternalDataJob")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.close_old_connections")+ @patch.object(CDCExtractActivity, "_pause_cdc_extraction_schedule")def test_analytics_failure_does_not_mask_nonretryable(self,+ _mock_pause_schedule,mock_close_conns,MockJob,MockSourceModel,@@ -2410,7 +2419,11 @@ class TestFailureVisibilityJobs:mock_activity.heartbeat = MagicMock()mock_activity.info.return_value = MagicMock(workflow_id="wf-1", workflow_run_id="run-1", attempt=attempt)- with pytest.raises((NonRetryableException, psycopg.OperationalError)):+ # The non-retryable pause hits Temporal (sync_connect); stub it so these stay off the network.+ with (+ patch.object(CDCExtractActivity, "_pause_cdc_extraction_schedule"),+ pytest.raises((NonRetryableException, psycopg.OperationalError)),+ ):cdc_extract_activity(CDCExtractInput(team_id=1, source_id=source.id))@parameterized.expand(