: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(warehouse-sources): stabilize parent snapshot test (#96139)
Paul D'Ambrab074442de1cf
diff --git a/.test_quarantine.json b/.test_quarantine.jsonindex 79b4e18df317..2af9ccf066aa 100644--- a/.test_quarantine.json+++ b/.test_quarantine.json@@ -39,16 +39,6 @@"added": "2026-08-10","expires": "2026-09-07","mode": "run"- },- {- "id": "products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_warehouse_parent.py::test_resolve_pins_to_last_completed_snapshot_while_parent_is_syncing",- "runner": "pytest",- "reason": "deltalake 1.6.1's load_as_version(timestamp) races with millisecond-resolution commit timestamps: when the pin timestamp equals the exact write time of the v0 commit, it can round to the next commit instead, so pinned.version becomes 1 instead of 0. Reproduced locally in isolation (pyarrow/deltalake only, no Django): 20/30 runs of the write->overwrite->load_as_version sequence landed one version past v0. This PR only touches the MongoDB source (mongo.py/test_mongo.py) and never imports warehouse_parent.py, so the timing race is pre-existing and unrelated.",- "owner": "@team-data-stack",- "issue": "https://github.com/PostHog/posthog/pull/93077",- "added": "2026-09-02",- "expires": "2026-09-16",- "mode": "run"}]}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_warehouse_parent.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_warehouse_parent.pyindex bb49a013bd2d..397da27aa9e3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_warehouse_parent.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_warehouse_parent.py@@ -1,4 +1,3 @@-import osfrom datetime import UTC, datetime, timedeltafrom pathlib import Pathfrom types import SimpleNamespace@@ -6,7 +5,7 @@ from typing import Anyimport pytestfrom posthog.test.base import APIBaseTest-from unittest.mock import patch+from unittest.mock import Mock, patchimport pyarrow as paimport deltalake@@ -175,30 +174,26 @@ def test_resolve_raises_when_parent_has_no_synced_table(tmp_path: Path) -> None:_patched_resolve(str(tmp_path / "does_not_exist"))-def _set_delta_commit_log_mtimes(uri: str, times_by_version: dict[int, datetime]) -> None:- # delta-rs resolves a time-travel pin against the `_delta_log` commit files' modification times,- # not the `timestamp` inside each commit that `DeltaTable.history()` reports. Those mtimes come- # from a coarse filesystem clock that can collapse the gap between two back-to-back writes, so- # the test sets them explicitly and stays about the pin rather than about the clock.- for version, committed_at in times_by_version.items():- ts = committed_at.timestamp()- os.utime(Path(uri) / "_delta_log" / f"{version:020d}.json", (ts, ts))---def test_resolve_pins_to_last_completed_snapshot_while_parent_is_syncing(tmp_path: Path) -> None:- uri = _write_parent_table(tmp_path)- v0 = deltalake.DeltaTable(uri).version()-- # An in-flight full refresh has already committed a partial overwrite on top of v0.- deltalake.write_deltalake(uri, pa.table({"id": ["partial"], "last_seen": ["x"], "title": ["y"]}), mode="overwrite")-+def test_resolve_pins_to_last_completed_snapshot_while_parent_is_syncing() -> None:snapshot_committed_at = datetime(2026, 3, 1, 12, 0, tzinfo=UTC)- _set_delta_commit_log_mtimes(uri, {v0: snapshot_committed_at, v0 + 1: snapshot_committed_at + timedelta(minutes=2)})+ delta_table = Mock()+ delta_table.history.return_value = [+ {"version": 1, "timestamp": int((snapshot_committed_at + timedelta(minutes=2)).timestamp() * 1000)},+ {"version": 0, "timestamp": int(snapshot_committed_at.timestamp() * 1000)},+ ]+ delta_table.version.return_value = 1- # The parent's last completed job finished after v0 landed and before the refresh started writing.- pinned = _patched_resolve(uri, snapshot_timestamp=snapshot_committed_at + timedelta(minutes=1))+ def load_as_version(version: int | datetime) -> None:+ delta_table.version.return_value = 1 if isinstance(version, datetime) else version++ delta_table.load_as_version.side_effect = load_as_version+ with patch.object(warehouse_parent.deltalake, "DeltaTable", return_value=delta_table) as delta_table_class:+ delta_table_class.is_deltatable.return_value = True+ pinned = _patched_resolve(+ "s3://warehouse/issues", snapshot_timestamp=snapshot_committed_at + timedelta(minutes=1)+ )- assert pinned.version == v0+ assert pinned.version == 0class TestParentSnapshotCoversThrough(APIBaseTest):