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): auto-heal delta tables with an orphaned _delta_log (#69204)

estefaniae5c0d2259a33
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py
index 659bd3af8595..f6b058e09046 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py
@@ -240,9 +240,14 @@ class DeltaTableHelper:
deltalake.DeltaTable, table_uri=delta_uri, storage_options=storage_options
)
except Exception as e:
- # Temp fix for bugged tables
capture_exception(e)
- if "parse decimal overflow" in "".join(e.args):
+ error_text = "".join(str(arg) for arg in e.args)
+ # Unrecoverable tables (bugged decimals, or an orphaned _delta_log missing its
+ # metadata action — impossible on a healthy table): wipe so the sync starts fresh.
+ if "parse decimal overflow" in error_text or "No table metadata or protocol found" in error_text:
+ await self._logger.aerror(
+ f"get_delta_table: deleting unrecoverable delta table for a fresh sync: {error_text}"
+ )
async with aget_s3_client() as s3:
await s3._rm(delta_uri, recursive=True)
else:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_delta_table_helper.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_delta_table_helper.py
index 1fc691e0fdce..424ca9520f85 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_delta_table_helper.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_delta_table_helper.py
@@ -270,6 +270,52 @@ class TestCompactIfFragmented:
mock_compact.assert_not_called()
+class TestGetDeltaTableUnrecoverableErrors:
+ # (case_name, error_message, expect_heal) — heal = wipe the table and fall back to first-sync mode
+ _ERROR_CASES: list[tuple[str, str, bool]] = [
+ (
+ "orphaned_delta_log",
+ "Kernel error: No table metadata or protocol found in delta log.",
+ True,
+ ),
+ ("bugged_decimal_data", "parse decimal overflow at column x", True),
+ ("other_errors_reraise", "Generic DeltaTable error: something else went wrong", False),
+ ]
+
+ @parameterized.expand(_ERROR_CASES)
+ @pytest.mark.asyncio
+ async def test_open_failure_handling(self, _name: str, error_message: str, expect_heal: bool):
+ helper = DeltaTableHelper(resource_name="t", job=MagicMock(), logger=_make_logger())
+ delta_uri = "s3://bucket/team_id/job_id/t"
+
+ s3 = MagicMock()
+ s3._rm = AsyncMock()
+ s3_cm = MagicMock()
+ s3_cm.__aenter__ = AsyncMock(return_value=s3)
+ s3_cm.__aexit__ = AsyncMock(return_value=False)
+
+ module = "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.delta_table_helper"
+ with (
+ patch.object(helper, "_get_delta_table_uri", AsyncMock(return_value=delta_uri)),
+ patch(f"{module}.deltalake.DeltaTable") as mock_delta_table,
+ patch(f"{module}.aget_s3_client", MagicMock(return_value=s3_cm)),
+ patch(f"{module}.capture_exception"),
+ ):
+ mock_delta_table.is_deltatable.return_value = True
+ mock_delta_table.side_effect = Exception(error_message)
+
+ if expect_heal:
+ result = await helper.get_delta_table()
+ assert result is None
+ assert helper.is_first_sync is True
+ s3._rm.assert_awaited_once_with(delta_uri, recursive=True)
+ else:
+ with pytest.raises(Exception, match="something else went wrong"):
+ await helper.get_delta_table()
+ s3._rm.assert_not_awaited()
+ assert helper.is_first_sync is False
+
+
class TestWriteToDeltalakeCommitMetadataPassThrough:
"""Covers that commit_metadata is forwarded to deltalake.write_deltalake as CommitProperties."""