: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(data-imports): treat the MySQL zero-date sentinel as absent in incremental cursors (#110531)
Tom Owersb1d347118551
diff --git a/products/warehouse_sources/backend/models/external_data_schema.py b/products/warehouse_sources/backend/models/external_data_schema.pyindex 6b1f05587236..4db56a6dea00 100644--- a/products/warehouse_sources/backend/models/external_data_schema.py+++ b/products/warehouse_sources/backend/models/external_data_schema.py@@ -1274,6 +1274,16 @@ class ExternalDataSchema( # nosemgrep: semgrep.rules.security.prefer-uuid7-djan# parse, even though the preceding GMT offset already fully specifies the instant.JS_DATE_TOSTRING_TZ_NAME_RE = re.compile(r"\([^()]*\)\s*\Z")+# MySQL's zero-date convention for "no date set" ('0000-00-00', optionally with a+# '00:00:00' time part). Some REST sources (e.g. ServiceM8's `edit_date`) emit this literal+# string too, and dateutil raises ParserError on the year-0 value rather than treating it+# as absent.+ZERO_DATETIME_SENTINEL_RE = re.compile(r"\A0000-00-00(?:[ T]00:00:00(?:\.0+)?)?\Z")+++def _is_zero_datetime_sentinel(value: str) -> bool:+ return bool(ZERO_DATETIME_SENTINEL_RE.match(value.strip()))+def _parse_datetime_string(value: str) -> datetime:try:@@ -1408,6 +1418,9 @@ def process_incremental_value(value: Any | None, field_type: IncrementalFieldTypif isinstance(value, int | float) and not isinstance(value, bool):return value+ if isinstance(value, str) and _is_zero_datetime_sentinel(value):+ return None+return _coerce_incremental_datetime(value)if field_type == IncrementalFieldType.Date:@@ -1420,6 +1433,9 @@ def process_incremental_value(value: Any | None, field_type: IncrementalFieldTypif isinstance(value, int | float) and not isinstance(value, bool):return value+ if isinstance(value, str) and _is_zero_datetime_sentinel(value):+ return None+parsed = _coerce_incremental_datetime(value)return parsed if isinstance(parsed, int) else parsed.date()diff --git a/products/warehouse_sources/backend/tests/test_models.py b/products/warehouse_sources/backend/tests/test_models.pyindex cff86f45e690..a50b83baeea4 100644--- a/products/warehouse_sources/backend/tests/test_models.py+++ b/products/warehouse_sources/backend/tests/test_models.py@@ -1175,6 +1175,12 @@ def test_process_incremental_value_xid_returns_value_as_is() -> None:# A genuine compact date string (YYYYMMDD) must still parse as a real date, not fall# back to the raw-integer path.("20240115", IncrementalFieldType.Date, date(2024, 1, 15)),+ # MySQL's zero-date sentinel for "no date set" (also emitted verbatim by some REST+ # sources, e.g. ServiceM8's `edit_date`) must be treated as absent instead of+ # crashing on dateutil's year-0 ParserError.+ ("0000-00-00 00:00:00", IncrementalFieldType.DateTime, None),+ ("0000-00-00 00:00:00", IncrementalFieldType.Timestamp, None),+ ("0000-00-00", IncrementalFieldType.Date, None),],)def test_process_incremental_value_datetime_handles_epoch_numbers(value, field_type, expected) -> None: