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(warehouse-sources): stamp Delta commit times in the snapshot pin test (#93155)

Paul D'Ambra5ee40defe921
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.py
index 229395479e96..bb49a013bd2d 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,4 @@
-import json
+import os
from datetime import UTC, datetime, timedelta
from pathlib import Path
from types import SimpleNamespace
@@ -175,21 +175,28 @@ 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_table = deltalake.DeltaTable(uri)
- v0 = v0_table.version()
- v0_timestamp = datetime.fromtimestamp(v0_table.history()[0]["timestamp"] / 1000, tz=UTC)
+ 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")
- partial_refresh_log = Path(uri) / "_delta_log" / "00000000000000000001.json"
- entries = partial_refresh_log.read_text().splitlines()
- partial_refresh_commit = json.loads(entries[0])
- partial_refresh_commit["commitInfo"]["timestamp"] = int(v0_timestamp.timestamp() * 1000) + 1
- partial_refresh_log.write_text("\n".join([json.dumps(partial_refresh_commit), *entries[1:]]) + "\n")
- pinned = _patched_resolve(uri, snapshot_timestamp=v0_timestamp)
+ 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)})
+
+ # 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))
assert pinned.version == v0