: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): let attio get endpoints resume at the saved offset (#112739)
Tom Owers8d6b902e57c8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/attio.py b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/attio.pyindex f990da3b0d81..6c7e77f2ef4f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/attio.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/attio.py@@ -211,19 +211,20 @@ def attio_source("resources": [get_resource(endpoint)],}- # Attio's GET endpoints do not expose a stable ordering. Their numeric offsets can skip a- # live row when an earlier item is deleted between attempts, so only the explicitly sorted- # POST endpoints may restore and save offsets.- supports_resume = endpoint_config.method == "POST"+ # The GET endpoints take no sort order, so a row deleted during the walk moves every later+ # offset down by one and the walk misses one live row. A resumed attempt has the same exposure+ # as one long attempt, because it continues at the offset after the last written page. Without+ # resume, a walk of a large workspace cannot move to another worker, and a restart reads every+ # page again.initial_paginator_state: Optional[dict[str, Any]] = None- if supports_resume and resumable_source_manager.can_resume():+ if resumable_source_manager.can_resume():resume = resumable_source_manager.load_state()if resume is not None:initial_paginator_state = {"offset": resume.offset}def save_checkpoint(state: Optional[dict[str, Any]]) -> None:- # The framework calls this after it yields a page, and the offset points at the page after- # it, so a resume never skips a page that the pipeline has not written.+ # The offset points at the page after the one that carries this state, so a resume never+ # skips a page that the pipeline has not written.if state and state.get("offset") is not None:resumable_source_manager.save_state(AttioResumeConfig(offset=int(state["offset"])))@@ -232,7 +233,7 @@ def attio_source(team_id,job_id,None,- resume_hook=save_checkpoint if supports_resume else None,+ resume_hook=save_checkpoint,initial_paginator_state=initial_paginator_state,).add_map(_flatten_item)@@ -246,5 +247,4 @@ def attio_source(partition_format="week",partition_keys=[endpoint_config.partition_key],sort_mode="asc",- supports_resume=supports_resume,)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/source.pyindex 14caeeb50e87..088497e2bd21 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/source.py@@ -43,15 +43,6 @@ class AttioSource(ResumableSource[AttioSourceConfig, AttioResumeConfig]):return CANONICAL_DESCRIPTIONS- def resume_covers_run(- self,- *,- incremental_or_append: bool,- schema_name: str | None = None,- ) -> bool:- endpoint = ATTIO_ENDPOINTS.get(schema_name or "")- return endpoint is None or endpoint.method == "POST"-def get_non_retryable_errors(self) -> dict[str, str | None]:return {"401 Client Error: Unauthorized for url: https://api.attio.com": "Your Attio API key is invalid or expired. Please generate a new key and reconnect.",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio.py b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio.pyindex 4fe9f15e20e0..7358d80e7a07 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio.py@@ -80,7 +80,7 @@ class TestAttioResume:rows = [row for page in cast(Iterable[list[dict[str, Any]]], response.items()) for row in page]return sent, rows- @pytest.mark.parametrize("endpoint", ["companies", "people", "deals"])+ @pytest.mark.parametrize("endpoint", ["companies", "people", "deals", "notes", "tasks"])def test_fresh_run_stages_next_offset_after_each_page(self, endpoint: str) -> None:limit = ATTIO_ENDPOINTS[endpoint].page_sizemanager = _make_manager()@@ -108,7 +108,7 @@ class TestAttioResume:assert len(rows) == 2manager.save_state.assert_not_called()- @pytest.mark.parametrize("endpoint", ["companies", "people"])+ @pytest.mark.parametrize("endpoint", ["companies", "people", "lists", "notes", "tasks", "workspace_members"])def test_resumed_run_starts_from_saved_offset(self, endpoint: str) -> None:limit = ATTIO_ENDPOINTS[endpoint].page_sizemanager = _make_manager(AttioResumeConfig(offset=2 * limit))@@ -120,16 +120,6 @@ class TestAttioResume:assert rows[0][ATTIO_ENDPOINTS[endpoint].primary_key] == f"row-{2 * limit}"assert [call.args[0] for call in manager.save_state.call_args_list] == [AttioResumeConfig(offset=3 * limit)]- @pytest.mark.parametrize("endpoint", ["lists", "notes", "tasks", "workspace_members"])- def test_get_endpoint_ignores_offset_checkpoint(self, endpoint: str) -> None:- manager = _make_manager(AttioResumeConfig(offset=ATTIO_ENDPOINTS[endpoint].page_size))-- sent, _ = self._drive(endpoint, manager, [_page(endpoint, 0, 1)])-- assert sent[0]["offset"] == 0- manager.load_state.assert_not_called()- manager.save_state.assert_not_called()-def test_resumed_query_keeps_sort_order_in_body(self) -> None:# Offsets only line up across runs when every run asks for the same order.manager = _make_manager(AttioResumeConfig(offset=500))diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio_source.pyindex ace6ac21b6e9..c2f74ca26da1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/attio/tests/test_attio_source.py@@ -9,12 +9,9 @@ class TestAttioSource:def setup_method(self):self.source = AttioSource()- @pytest.mark.parametrize(- "schema_name,expected",- [("companies", True), ("notes", False), ("tasks", False)],- )- def test_retry_budget_only_covers_sorted_post_endpoints(self, schema_name, expected):- assert self.source.resume_covers_run(incremental_or_append=False, schema_name=schema_name) is expected+ @pytest.mark.parametrize("schema_name", ["companies", "notes", "tasks"])+ def test_retry_budget_covers_every_endpoint(self, schema_name):+ assert self.source.resume_covers_run(incremental_or_append=False, schema_name=schema_name)@pytest.mark.parametrize("pattern",