: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-warehouse): keep linear progress columns as float (#72404)
Kyle Swank6d7cf0c9f261
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.pyindex ff4fde0d31a7..2d5d2aa1ab2a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.py@@ -59,6 +59,28 @@ def _wait_strategy(retry_state: RetryCallState) -> float:return _LINEAR_FALLBACK_WAIT(retry_state)+# Linear returns `progress` as a Float in [0, 1], but whole values (0, 1) arrive over JSON+# without a decimal point. If the batch that first creates the Delta table has only whole+# values, the column infers as int64 and the first fractional progress (e.g. 0.539474) then+# fails every later sync with ArrowInvalid, wedging the table. Force these columns to float+# so the inferred type is stable regardless of which rows land first.+_FLOAT_FIELDS: dict[str, tuple[str, ...]] = {+ "cycles": ("progress",),+ "projects": ("progress",),+}+++def _coerce_float_fields(nodes: list[dict[str, Any]], endpoint_name: str) -> None:+ field_names = _FLOAT_FIELDS.get(endpoint_name)+ if not field_names:+ return+ for node in nodes:+ for field_name in field_names:+ value = node.get(field_name)+ if value is not None:+ node[field_name] = float(value)++@dataclasses.dataclassclass LinearResumeConfig:cursor: str@@ -163,6 +185,7 @@ def _make_paginated_request(payload = execute(variables)data = payload["data"][graphql_query_name]["nodes"]+ _coerce_float_fields(data, endpoint_name)yield datapage_info = payload["data"][graphql_query_name]["pageInfo"]diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.pyindex f1be6dd44f5c..83fa369f2811 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py@@ -38,6 +38,17 @@ def _make_response(nodes: list[dict[str, Any]], has_next_page: bool, end_cursor:return response+def _make_response_for(query_name: str, nodes: list[dict[str, Any]]) -> MagicMock:+ """Single-page response keyed under an arbitrary GraphQL query name (e.g. cycles/projects)."""+ response = MagicMock()+ response.status_code = 200+ response.ok = True+ response.json.return_value = {+ "data": {query_name: {"nodes": nodes, "pageInfo": {"hasNextPage": False, "endCursor": None}}}+ }+ return response++def _make_rate_limited_response(headers: dict[str, str] | None = None) -> MagicMock:"""Mimic Linear's HTTP-level 429: an HTML body that fails JSON parsing."""response = MagicMock()@@ -366,6 +377,36 @@ class TestMakePaginatedRequest:assert "secret customer issue" not in str(exc_info.value)+class TestFloatFieldCoercion:+ @parameterized.expand([("cycles",), ("projects",)])+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.linear.linear.make_tracked_session")+ def test_whole_number_progress_is_coerced_to_float(self, endpoint_name: str, mock_session_cls: MagicMock) -> None:+ # Whole progress values (0, 1) arrive as JSON ints. Left as ints, a table-creating batch of+ # only whole values infers int64 and the first fractional progress wedges the sync with+ # ArrowInvalid. The source must yield floats so the column always infers as float64.+ session = MagicMock()+ session.post.side_effect = [+ _make_response_for(+ endpoint_name,+ [{"id": "a", "progress": 0}, {"id": "b", "progress": 1}, {"id": "c", "progress": None}],+ )+ ]+ mock_session_cls.return_value = session++ pages = list(+ _make_paginated_request(+ access_token="tok",+ endpoint_name=endpoint_name,+ logger=MagicMock(),+ resumable_source_manager=_make_resumable_manager(),+ )+ )++ progress_values = [node["progress"] for node in pages[0]]+ assert progress_values == [0.0, 1.0, None]+ assert all(isinstance(v, float) for v in progress_values if v is not None)++class TestRateLimitBackoff:@parameterized.expand([