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-imports): accept date values on datetime incremental cursors (#110195)

Tom Owersfc4100a1454d
diff --git a/products/warehouse_sources/backend/models/external_data_schema.py b/products/warehouse_sources/backend/models/external_data_schema.py
index 4db56a6dea00..c526d2f0ba81 100644
--- a/products/warehouse_sources/backend/models/external_data_schema.py
+++ b/products/warehouse_sources/backend/models/external_data_schema.py
@@ -6,7 +6,7 @@ from collections.abc import Callable, Generator, Iterable
from contextlib import contextmanager
from contextvars import ContextVar
from dataclasses import dataclass
-from datetime import UTC, date, datetime, timedelta
+from datetime import UTC, date, datetime, time, timedelta
from functools import partial
from typing import TYPE_CHECKING, Any, Literal, Optional
@@ -1413,6 +1413,11 @@ def process_incremental_value(value: Any | None, field_type: IncrementalFieldTyp
if isinstance(value, datetime):
return value
+ # A date-only column (e.g. a MySQL DATE) can back a DateTime/Timestamp field when the column
+ # type changed after the incremental field was saved.
+ if isinstance(value, date):
+ return datetime.combine(value, time.min)
+
# Some sources (e.g. Stripe `created`) expose datetime cursors as Unix-epoch numbers.
# dateutil can't parse a non-string, so pass epochs through unchanged for the source query.
if isinstance(value, int | float) and not isinstance(value, bool):
diff --git a/products/warehouse_sources/backend/tests/test_models.py b/products/warehouse_sources/backend/tests/test_models.py
index a50b83baeea4..d51a815a17bb 100644
--- a/products/warehouse_sources/backend/tests/test_models.py
+++ b/products/warehouse_sources/backend/tests/test_models.py
@@ -1150,6 +1150,8 @@ def test_process_incremental_value_xid_returns_value_as_is() -> None:
(1718377611.5, IncrementalFieldType.DateTime, 1718377611.5),
(datetime(2024, 6, 14, 15, 33, 31), IncrementalFieldType.DateTime, datetime(2024, 6, 14, 15, 33, 31)),
("2024-06-14T15:33:31", IncrementalFieldType.DateTime, datetime(2024, 6, 14, 15, 33, 31)),
+ (date(2024, 6, 14), IncrementalFieldType.DateTime, datetime(2024, 6, 14)),
+ (date(2024, 6, 14), IncrementalFieldType.Timestamp, datetime(2024, 6, 14)),
("2024-06-14", IncrementalFieldType.Date, date(2024, 6, 14)),
# JS `Date.prototype.toString()` cursors carry a parenthetical timezone name dateutil
# can't parse on its own, even though the GMT offset earlier in the string is sufficient.