: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(zoho_crm): treat a 304 conditional read as no new records (#97243)
Tom Owerscae93428172a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/zoho_crm/tests/test_zoho_crm.py b/products/warehouse_sources/backend/temporal/data_imports/sources/zoho_crm/tests/test_zoho_crm.pyindex 6c4bb283d97f..d3e912d65219 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/zoho_crm/tests/test_zoho_crm.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/zoho_crm/tests/test_zoho_crm.py@@ -59,6 +59,13 @@ def _response(status_code: int = 200, body: Optional[dict[str, Any]] = None) ->return response+def _no_content_response(status_code: int) -> mock.MagicMock:+ """An empty-bodied Zoho response: reading it as JSON fails, as it does against the real API."""+ response = _response(status_code)+ response.json.side_effect = requests.exceptions.JSONDecodeError("Expecting value", "", 0)+ return response++def _token_response(api_domain: str = "https://www.zohoapis.com") -> mock.MagicMock:return _response(200, {"access_token": "access-token", "api_domain": api_domain, "expires_in": 3600})@@ -191,13 +198,14 @@ class TestZohoCRMClient:assert response.status_code == 200assert session.post.call_count == 2+ @pytest.mark.parametrize("status_code", [204, 304])@mock.patch(f"{_MODULE}.make_tracked_session")- def test_204_is_returned_without_raising(self, make_session: mock.MagicMock) -> None:- no_content = _response(204)- no_content.raise_for_status.side_effect = AssertionError("204 must not be treated as an error")+ def test_no_content_is_returned_without_raising(self, make_session: mock.MagicMock, status_code: int) -> None:+ no_content = _no_content_response(status_code)+ no_content.raise_for_status.side_effect = AssertionError(f"{status_code} must not be treated as an error")make_session.return_value = _session([no_content])- assert _client().get("/crm/v8/Leads").status_code == 204+ assert _client().get("/crm/v8/Leads").status_code == status_code@mock.patch(f"{_MODULE}.make_tracked_session")def test_session_disables_sample_capture_and_redacts_credentials(self, make_session: mock.MagicMock) -> None:@@ -231,9 +239,10 @@ class TestReadableFieldNames:assert readable_field_names(_client(), "v8", "Leads") == ["Last_Name", "No_View_Type"]+ @pytest.mark.parametrize("status_code", [204, 304])@mock.patch(f"{_MODULE}.make_tracked_session")- def test_204_metadata_yields_no_projection(self, make_session: mock.MagicMock) -> None:- make_session.return_value = _session([_response(204)])+ def test_no_content_metadata_yields_no_projection(self, make_session: mock.MagicMock, status_code: int) -> None:+ make_session.return_value = _session([_no_content_response(status_code)])assert readable_field_names(_client(), "v8", "Leads") == []@@ -326,9 +335,10 @@ class TestGetRows:assert list(get_rows(_client(), "v8", "Leads", FakeResumeManager(), mock.MagicMock())) == []assert session.get.call_count == 2+ @pytest.mark.parametrize("status_code", [204, 304])@mock.patch(f"{_MODULE}.make_tracked_session")- def test_204_module_response_yields_nothing(self, make_session: mock.MagicMock) -> None:- session = _session([_fields_response(1), _response(204)])+ def test_no_content_module_response_yields_nothing(self, make_session: mock.MagicMock, status_code: int) -> None:+ session = _session([_fields_response(1), _no_content_response(status_code)])make_session.return_value = sessionassert list(get_rows(_client(), "v8", "Leads", FakeResumeManager(), mock.MagicMock())) == []diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/zoho_crm/zoho_crm.py b/products/warehouse_sources/backend/temporal/data_imports/sources/zoho_crm/zoho_crm.pyindex 1eacdb111f38..85832c9bbda9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/zoho_crm/zoho_crm.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/zoho_crm/zoho_crm.py@@ -39,6 +39,11 @@ ZOHO_REGIONS: dict[str, RegionHosts] = {"cn": RegionHosts(accounts_host="https://accounts.zoho.com.cn", api_domain="https://www.zohoapis.com.cn"),}+# Zoho answers a request that matched nothing with 204. It answers a conditional read whose+# records are all older than `If-Modified-Since` with 304. Both bodies are empty, and+# `raise_for_status()` lets 304 through, so each read site must check for both.+NO_CONTENT_STATUSES = frozenset({204, 304})+# Zoho caps `per_page` at 200.PAGE_SIZE = 200# `page`-based pagination stops at 2000 records (page * per_page); past that Zoho only@@ -176,8 +181,7 @@ class ZohoCRMClient:self.mint_access_token()response = _send()- # 204 is Zoho's "nothing matched" — an empty body, not an error.- if response.status_code != 204:+ if response.status_code not in NO_CONTENT_STATUSES:response.raise_for_status()return response@@ -185,7 +189,7 @@ class ZohoCRMClient:def readable_field_names(client: ZohoCRMClient, api_version: str, module: str) -> list[str]:"""Field API names Get Records can project for `module`, from the fields metadata API."""response = client.get(f"/crm/{api_version}/settings/fields", params={"module": module})- if response.status_code == 204:+ if response.status_code in NO_CONTENT_STATUSES:return []names: list[str] = []@@ -209,7 +213,7 @@ def _fetch_page(headers: dict[str, str],) -> tuple[list[dict[str, Any]], dict[str, Any]]:response = client.get(f"/crm/{api_version}/{config.path}", params=params, headers=headers)- if response.status_code == 204:+ if response.status_code in NO_CONTENT_STATUSES:return [], {}body = response.json()