: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): floor Mercury incremental start to date-only (#74023)
Kyle Swankcf4541952d30
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/mercury.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/mercury.pyindex 5a3a5014ff28..47cc9e7a22dd 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/mercury.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/mercury.py@@ -1,5 +1,5 @@import dataclasses-from datetime import date, datetime+from datetime import UTC, date, datetimefrom typing import Any, Optionalfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session@@ -31,12 +31,23 @@ class MercuryResumeConfig:def format_incremental_value(value: Any) -> str | None:- """Format the incremental watermark as ISO 8601, which Mercury's date filters accept."""+ """Floor the incremental watermark to a yyyy-mm-dd string.++ Mercury's `start` filter accepts "YYYY-MM-DD or an ISO 8601 string", but a naive ISO datetime with+ microseconds (what `datetime.isoformat()` emits for a tz-naive watermark, e.g.+ `2026-06-19T18:54:04.991622`) is rejected with a 400. Flooring to the UTC date sidesteps the+ precision/offset fragility entirely. Re-querying from the floored day re-reads that whole day, which+ merge dedupes on the primary key — so the incremental sync is self-healing even though the filter is+ coarser than the cursor.+ """if value is None:return None- if isinstance(value, datetime | date):+ if isinstance(value, datetime):+ aware = value if value.tzinfo is not None else value.replace(tzinfo=UTC)+ return aware.astimezone(UTC).date().isoformat()+ if isinstance(value, date):return value.isoformat()- return str(value)+ return str(value)[:10]def get_resource(name: str, should_use_incremental_field: bool) -> EndpointResource:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/tests/test_mercury.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/tests/test_mercury.pyindex ea432397e154..f944b4d7303e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/tests/test_mercury.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/tests/test_mercury.py@@ -30,9 +30,10 @@ class TestFormatIncrementalValue:("value", "expected"),[(None, None),- (datetime(2026, 1, 2, 3, 4, 5, tzinfo=UTC), "2026-01-02T03:04:05+00:00"),+ (datetime(2026, 1, 2, 3, 4, 5, tzinfo=UTC), "2026-01-02"),+ (datetime(2026, 1, 2, 3, 4, 5), "2026-01-02"),(date(2026, 1, 2), "2026-01-02"),- ("2026-01-02T03:04:05Z", "2026-01-02T03:04:05Z"),+ ("2026-01-02T03:04:05Z", "2026-01-02"),],)def test_formats_watermark_for_the_api(self, value: Any, expected: str | None) -> None:@@ -194,7 +195,7 @@ class TestMercurySourceResumeBehavior:manager.save_state.assert_not_called()- def test_incremental_sync_sends_iso_start_watermark(self) -> None:+ def test_incremental_sync_sends_date_only_start_watermark(self) -> None:manager = MagicMock(spec=ResumableSourceManager)manager.can_resume.return_value = False@@ -209,7 +210,7 @@ class TestMercurySourceResumeBehavior:db_incremental_field_last_value=datetime(2026, 1, 2, 3, 4, 5, tzinfo=UTC),)- assert sent_params[0]["start"] == "2026-01-02T03:04:05+00:00"+ assert sent_params[0]["start"] == "2026-01-02"assert sent_params[0]["order"] == "asc"def test_first_incremental_sync_without_watermark_omits_start(self) -> None: