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(ws): stop deleting S3 parquet files on extraction failure in pipeline_v3 (#61430)

estefaniad941b88a7a52
diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/pipeline.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/pipeline.py
index 52220b2fd7d1..37427e052c29 100644
--- a/posthog/temporal/data_imports/pipelines/pipeline_v3/pipeline.py
+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/pipeline.py
@@ -276,10 +276,6 @@ class PipelineV3(Generic[ResumableData]):
except Exception:
status = "error"
self._logger.exception("V3 Pipeline: Extraction failed")
- try:
- self._s3_batch_writer.cleanup()
- except Exception:
- self._logger.exception("V3 Pipeline: Failed to clean up S3 resources")
raise
finally:
duration = time.perf_counter() - start_time
diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/test_pipeline.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/test_pipeline.py
new file mode 100644
index 000000000000..7bd16171cfb9
--- /dev/null
+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/test_pipeline.py
@@ -0,0 +1,73 @@
+from typing import cast
+
+import pytest
+from unittest.mock import AsyncMock, MagicMock, patch
+
+from posthog.temporal.data_imports.pipelines.pipeline_v3.pipeline import PipelineV3
+
+
+def _make_logger() -> MagicMock:
+ logger = MagicMock()
+ logger.adebug = AsyncMock()
+ logger.ainfo = AsyncMock()
+ logger.awarning = AsyncMock()
+ logger.aerror = AsyncMock()
+ logger.exception = MagicMock()
+ return logger
+
+
+def _make_pipeline() -> PipelineV3:
+ """Build a PipelineV3 with just enough wiring to exercise run()."""
+ with patch.object(PipelineV3, "__init__", return_value=None):
+ pipeline = PipelineV3.__new__(PipelineV3)
+
+ pipeline._resource = MagicMock(name="test_table", primary_keys=["id"])
+ pipeline._resource_name = "test_table"
+ pipeline._job = MagicMock(team_id=1, workflow_run_id="run-abc", billable=False)
+ pipeline._source = MagicMock(source_type="Postgres")
+ pipeline._schema = MagicMock(
+ id="schema-1",
+ source_id="source-1",
+ is_incremental=False,
+ is_webhook=False,
+ is_append=False,
+ table=None,
+ )
+ pipeline._table = None
+ pipeline._logger = _make_logger()
+ pipeline._is_incremental = False
+ pipeline._reset_pipeline = False
+ pipeline._delta_table_helper = MagicMock(is_first_sync=True)
+ pipeline._resumable_source_manager = None
+ pipeline._internal_schema = MagicMock()
+ pipeline._cdp_producer = MagicMock()
+ pipeline._batcher = MagicMock()
+ pipeline._load_id = 1
+ pipeline._s3_batch_writer = MagicMock()
+ pipeline._pg_producer = MagicMock(sync_type="full_refresh")
+ pipeline._accumulated_pa_schema = None
+ pipeline._batch_results = []
+ pipeline._shutdown_monitor = MagicMock()
+
+ return pipeline
+
+
+class TestExtractionFailureDoesNotCleanupS3:
+ @pytest.mark.asyncio
+ async def test_s3_files_preserved_when_extraction_fails(self) -> None:
+ pipeline = _make_pipeline()
+ s3_writer = cast(MagicMock, pipeline._s3_batch_writer)
+
+ with (
+ patch(
+ "posthog.temporal.data_imports.pipelines.pipeline_v3.pipeline.cdp_producer_clear_chunks",
+ side_effect=RuntimeError("simulated extraction failure"),
+ ),
+ patch("posthog.temporal.data_imports.pipelines.pipeline_v3.pipeline.activity") as mock_activity,
+ ):
+ mock_activity.in_activity.return_value = False
+
+ with pytest.raises(RuntimeError, match="simulated extraction failure"):
+ await pipeline.run()
+
+ s3_writer.cleanup.assert_not_called()