: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-imports): don't let delta-table cleanup mask the real import error (#65707)
Tom Owers1bacbeffa67c
diff --git a/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr b/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambrindex a1c0325ab25a..0839c952c78f 100644--- a/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr+++ b/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr@@ -11,14 +11,6 @@OR query @? '$.** ? (@.kind == "InsightVizNode" &&(!exists(@.version) || @.version == null || @.version < 4)- )'- OR query @? '$.** ? (- @.kind == "RetentionQuery" &&- (!exists(@.version) || @.version == null || @.version < 2)- )'- OR query @? '$.** ? (- @.kind == "StickinessQuery" &&- (!exists(@.version) || @.version == null || @.version < 2))'OR query @? '$.** ? (@.kind == "TrendsQuery" &&diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/pipeline.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/pipeline.pyindex 4bf68a77dc1e..6c39b61984b5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/pipeline.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/pipeline.py@@ -268,12 +268,19 @@ class PipelineNonDLT(Generic[ResumableData]):return {"should_trigger_cdp_producer": await self._cdp_producer.should_produce_table()}finally:- # Help reduce the memory footprint of each job+ # Help reduce the memory footprint of each job. This is best-effort cleanup:+ # `get_delta_table` does object-storage I/O, so a transient storage blip here+ # must not mask the real import error from the try body — which drives+ # retry classification and the user-facing message — nor fail an otherwise+ # successful sync.await self._logger.adebug("Cleaning up delta table helper")- delta_table = await self._delta_table_helper.get_delta_table()- self._delta_table_helper.get_delta_table.cache_clear()- if delta_table:- del delta_table+ try:+ delta_table = await self._delta_table_helper.get_delta_table()+ self._delta_table_helper.get_delta_table.cache_clear()+ if delta_table:+ del delta_table+ except Exception:+ await self._logger.aexception("Failed to clean up delta table helper")del self._resourcedel self._delta_table_helperdiff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline.pyindex 6dc0eec806fe..8890a3c6b2da 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline.py@@ -2,10 +2,17 @@ import timeimport asyncioimport threadingimport contextvars+from typing import castimport pytest+from unittest.mock import AsyncMock-from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.pipeline import async_iterate+from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.cdp_producer import CDPProducer+from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.pipeline import (+ PipelineNonDLT,+ async_iterate,+)+from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceResponse_probe: contextvars.ContextVar[str | None] = contextvars.ContextVar("probe", default=None)@@ -92,3 +99,35 @@ async def test_async_iterate_close_runs_when_cancelled_mid_iteration():# close() must have run despite cancellation mid-iteration.assert closed_flag.wait(timeout=3.0), "iterator.close() was not called"+++async def test_run_cleanup_failure_does_not_mask_import_error(monkeypatch):+ # Regression: run()'s finally calls get_delta_table() (object-storage I/O) purely for+ # memory cleanup. When that raised — e.g. a transient object-storage blip — it replaced+ # the in-flight import error, so a connection failure already classified as non-retryable+ # surfaced as the unrelated cleanup error and the job retried to its maximum instead of+ # stopping. The body error must propagate; the cleanup error must be swallowed.+ pipeline = PipelineNonDLT.__new__(PipelineNonDLT)+ pipeline._logger = AsyncMock()+ pipeline._resumable_source_manager = None+ pipeline._cdp_producer = cast(CDPProducer, object()) # unused: the patched clear-chunks ignores it+ pipeline._resource = cast(SourceResponse, object())+ pipeline._delta_table_helper = AsyncMock()+ pipeline._delta_table_helper.get_delta_table.side_effect = OSError("object storage unavailable")++ class ImportError_(Exception):+ pass++ async def _raise_import_error(_cdp_producer):+ raise ImportError_("Can't connect to MySQL server on")++ monkeypatch.setattr(+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.pipeline.cdp_producer_clear_chunks",+ _raise_import_error,+ )++ with pytest.raises(ImportError_, match="Can't connect to MySQL server on"):+ await pipeline.run()++ pipeline._logger.aexception.assert_awaited_once_with("Failed to clean up delta table helper")