: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(google_search_console): retry read timeouts inline like other transient network errors (#88429)
Tom Owers15e28e843ec8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.pyindex 506d1cfbf9e4..56510a276b24 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py@@ -340,17 +340,18 @@ def _query_search_analytics(_throttle(site_url)try:response = session.post(url, json=body)- except requests.ConnectionError:- # A dropped connection (RemoteDisconnected / connection reset) is raised before any- # response, so the quota/5xx handling below never sees it, and the tracked adapter's- # retry skips it because searchAnalytics.query is a POST. It's transient, so retry- # inline like a 5xx; once the inline budget is spent, let it bubble so Temporal- # retries the activity (resuming from the last saved date).+ except (requests.ConnectionError, requests.Timeout):+ # A dropped connection (RemoteDisconnected / connection reset) or a read timeout is+ # raised before any response, so the quota/5xx handling below never sees it, and the+ # tracked adapter's retry skips it because searchAnalytics.query is a POST. `Timeout`+ # covers `ReadTimeout`, which isn't a `ConnectionError` subclass. Both are transient,+ # so retry inline like a 5xx; once the inline budget is spent, let it bubble so+ # Temporal retries the activity (resuming from the last saved date).if attempt == QUOTA_MAX_RETRIES:raisewait = QUOTA_BACKOFF_BASE_SECONDS * (2**attempt)logger.warning(- "GSC request connection error, backing off",+ "GSC request connection/timeout error, backing off",site_url=site_url,attempt=attempt,wait_seconds=wait,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.pyindex 4e63fe647cab..724de2036943 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py@@ -848,6 +848,38 @@ def test_query_connection_error_bubbles_after_max_retries(monkeypatch):assert session.post.call_count == QUOTA_MAX_RETRIES + 1+def test_query_retries_read_timeout_then_succeeds(monkeypatch):+ monkeypatch.setattr(gsc.time, "sleep", lambda _s: None)+ monkeypatch.setattr(gsc, "_throttle", lambda _site: None)++ session = mock.MagicMock()+ session.post.side_effect = [+ requests.ReadTimeout("Read timed out."),+ requests.ReadTimeout("Read timed out."),+ _fake_response(200, {"rows": [{"keys": ["2026-04-15"], "clicks": 1}]}),+ ]++ rows = _query_search_analytics(session, "sc-domain:example.com", "2026-04-15", "2026-04-15", ["date"], 0)++ assert rows == [{"keys": ["2026-04-15"], "clicks": 1}]+ assert session.post.call_count == 3+++def test_query_read_timeout_bubbles_after_max_retries(monkeypatch):+ monkeypatch.setattr(gsc.time, "sleep", lambda _s: None)+ monkeypatch.setattr(gsc, "_throttle", lambda _site: None)++ session = mock.MagicMock()+ session.post.side_effect = requests.ReadTimeout("Read timed out.")++ # A persistent read timeout exhausts the inline budget and surfaces the real+ # ReadTimeout (retryable at the activity level).+ with pytest.raises(requests.ReadTimeout):+ _query_search_analytics(session, "sc-domain:example.com", "2026-04-15", "2026-04-15", ["date"], 0)++ assert session.post.call_count == QUOTA_MAX_RETRIES + 1++def test_query_retries_transient_token_refresh_error_then_succeeds(monkeypatch):monkeypatch.setattr(gsc.time, "sleep", lambda _s: None)monkeypatch.setattr(gsc, "_throttle", lambda _site: None)