: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(clerk): skip non-numeric timestamp fields instead of crashing (#75035)
Tom Owers72289d87c80b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/clerk.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/clerk.pyindex f864694f2733..1928af5fac39 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/clerk.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/clerk.py@@ -163,10 +163,14 @@ TIMESTAMP_FIELDS = [def _convert_timestamps(item: dict[str, Any]) -> dict[str, Any]:"""Convert Clerk timestamp fields from milliseconds to seconds."""for field in TIMESTAMP_FIELDS:- if field in item and item[field] is not None:- # Clerk returns timestamps in milliseconds, convert to seconds- # Use integer division to maintain int64 type for delta table compatibility- item[field] = item[field] // 1000+ value = item.get(field)+ # Some endpoints return these fields as an ISO string (or other non-numeric shape)+ # rather than epoch milliseconds; leave those untouched instead of crashing on `//`.+ # bool is an int subclass, so exclude it explicitly.+ if isinstance(value, int) and not isinstance(value, bool):+ # Clerk returns timestamps in milliseconds, convert to seconds.+ # Use integer division to maintain int64 type for delta table compatibility.+ item[field] = value // 1000return itemdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk.pyindex ad36187abee7..e5c11e118d5b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk.py@@ -304,6 +304,19 @@ class TestClerkEndpoints:for field, value in item.items():assert converted[field] == (value // 1000 if value is not None else None)+ @pytest.mark.parametrize(+ "value",+ [+ "2026-07-29T12:52:50Z", # ISO string instead of epoch ms+ "1700000000000", # numeric string+ True, # bool is an int subclass but not a timestamp+ ],+ )+ def test_non_integer_timestamps_pass_through_unchanged(self, value: Any) -> None:+ # Clerk occasionally returns a timestamp field as a non-numeric value; `//` on it used+ # to raise TypeError and abort the whole import.+ assert _convert_timestamps({"created_at": value}) == {"created_at": value}+@pytest.mark.parametrize("item,paths,expected",[