: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): don't parse ignored REST responses as JSON (#78746)
Tom Owers60854f77c444
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/config_setup.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/config_setup.pyindex 86e6032c0410..5a871312804f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/config_setup.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/config_setup.py@@ -367,7 +367,9 @@ def _create_response_actions_hook(action_type = matched.get("action") if matched else Noneif action_type == "ignore":- logger.info(f"Ignoring response with code {response.status_code} and content '{response.json()}'.")+ # Use response.text, not response.json(): an ignored response (e.g. a 404) often has an+ # empty or non-JSON body, and parsing it here would raise before the ignore takes effect.+ logger.info(f"Ignoring response with code {response.status_code} and content '{response.text[:500]}'.")raise IgnoreResponseException# Re-issue the request. This is how a source classifies an HTTP-200 body-level errordiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_response_action_classification.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_response_action_classification.pyindex 3b3aedb2c7b0..331d28eef34c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_response_action_classification.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_response_action_classification.py@@ -84,6 +84,30 @@ class TestResponseActionClassification:# Permanent: raised on the first response, never retried.assert mock_session.send.call_count == 1+ @patch("tenacity.nap.time.sleep")+ @patch(f"{MODULE}.make_tracked_session")+ def test_ignore_action_with_non_json_body_is_skipped(self, MockSession, _sleep) -> None:+ mock_session = MockSession.return_value+ mock_session.headers = {}+ mock_session.prepare_request.return_value = MagicMock()+ # A 404 whose body is empty (not JSON) — the shape an endpoint returns for a missing+ # resource. The ignore must skip it, not blow up parsing the body.+ resp = Response()+ resp.status_code = 404+ resp.reason = "Not Found"+ resp._content = b""+ resp.url = "https://api.example.com/items"+ mock_session.send.return_value = resp+ hooks = create_response_hooks([{"status_code": 404, "action": "ignore"}])++ client = RESTClient(base_url="https://api.example.com", max_retry_attempts=1)+ pages = list(+ client.paginate(path="/items", data_selector="results", paginator=SinglePagePaginator(), hooks=hooks)+ )++ assert pages == []+ assert mock_session.send.call_count == 1+@patch("tenacity.nap.time.sleep")@patch(f"{MODULE}.make_tracked_session")def test_unmatched_4xx_still_raises_for_status(self, MockSession, _sleep) -> None: