Skip to content

: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.

fix(shopify): retry 408 Request Timeout from the Admin API like a 5xx (#130458)

Tom Owers7e414d618304
diff --git a/products/warehouse_sources/sources/shopify/shopify.py b/products/warehouse_sources/sources/shopify/shopify.py
index b41ee5ae9f77..14453b906f03 100644
--- a/products/warehouse_sources/sources/shopify/shopify.py
+++ b/products/warehouse_sources/sources/shopify/shopify.py
@@ -415,8 +415,13 @@ def iter_shopify_pages(
raise ShopifyRetryableError(
f"Shopify: internal error from request {response.status_code} {response.reason}"
)
- else:
- response.raise_for_status()
+ if response.status_code == 408:
+ # Shopify's edge timed out waiting on the request rather than refusing it; retrying
+ # the identical request is the recovery, same as a 5xx.
+ raise ShopifyRetryableError(
+ f"Shopify: request timeout from request {response.status_code} {response.reason}"
+ )
+ response.raise_for_status()
payload = response.json()
retryable_error = _get_retryable_error(payload)
if retryable_error:
diff --git a/products/warehouse_sources/sources/shopify/source.py b/products/warehouse_sources/sources/shopify/source.py
index 96630cb8ff56..7d7b1734ab4b 100644
--- a/products/warehouse_sources/sources/shopify/source.py
+++ b/products/warehouse_sources/sources/shopify/source.py
@@ -274,6 +274,9 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):
"Shopify: rate limit exceeded",
"Shopify: internal error",
"Shopify: connection broken while reading response",
+ # Exhausted retries of a 408 from the Admin API GraphQL endpoint — Shopify's edge
+ # timed out, not a permanent rejection, so it's self-recovering like the 5xx case above.
+ "Shopify: request timeout",
# `_get_shopify_access_token` raises this once its own tenacity retries (same 5-attempt
# budget) are exhausted for a 429/5xx from the OAuth token endpoint — the same
# self-recovering contract as the GraphQL messages above.
diff --git a/products/warehouse_sources/sources/shopify/tests/test_non_retryable_errors.py b/products/warehouse_sources/sources/shopify/tests/test_non_retryable_errors.py
index 21c644c5e634..0b7456d36fe2 100644
--- a/products/warehouse_sources/sources/shopify/tests/test_non_retryable_errors.py
+++ b/products/warehouse_sources/sources/shopify/tests/test_non_retryable_errors.py
@@ -85,6 +85,7 @@ def test_admin_api_store_not_found_is_non_retryable(status_code, reason):
@pytest.mark.parametrize(
"status_code,reason",
[
+ (408, "Request Timeout"),
(429, "Too Many Requests"),
(500, "Internal Server Error"),
(502, "Bad Gateway"),
@@ -106,6 +107,7 @@ def test_transient_http_errors_stay_retryable(status_code, reason):
"Shopify: internal error from request 500 Internal Server Error",
'Shopify: internal errors in payload [{"message": "internal error", "extensions": {"code": "internal_server_error"}}]',
"Shopify: connection broken while reading response: Connection broken: IncompleteRead(0 bytes read)",
+ "Shopify: request timeout from request 408 Request Timeout",
"Failed to retrieve Shopify access token: 500 Internal Server Error",
"Failed to retrieve Shopify access token: 429 Too Many Requests",
],
diff --git a/products/warehouse_sources/sources/shopify/tests/test_rate_limit_retry.py b/products/warehouse_sources/sources/shopify/tests/test_rate_limit_retry.py
index aa64661f82e9..d27f3f7e1b4e 100644
--- a/products/warehouse_sources/sources/shopify/tests/test_rate_limit_retry.py
+++ b/products/warehouse_sources/sources/shopify/tests/test_rate_limit_retry.py
@@ -97,6 +97,48 @@ def _ok_page() -> MagicMock:
return response
+def _real_response(status_code: int, reason: str) -> requests.Response:
+ # A real Response, not a MagicMock, so `raise_for_status` behaves exactly as it does in
+ # production rather than whatever a mock is told to do.
+ response = requests.models.Response()
+ response.status_code = status_code
+ response.reason = reason
+ response.url = "https://example.invalid/graphql"
+ return response
+
+
+@patch("tenacity.nap.time.sleep")
+def test_request_retries_408_then_succeeds(_mock_sleep):
+ # Shopify's edge timed out waiting on the request rather than refusing it; the import should
+ # reissue it like a 5xx, not fail outright.
+ sess = MagicMock()
+ sess.post.side_effect = [_real_response(408, "Request Timeout"), _ok_page()]
+
+ batches = list(
+ _make_paginated_shopify_request(
+ "https://example.invalid/graphql", sess, SHOPIFY_GRAPHQL_OBJECTS[ABANDONED_CHECKOUTS], MagicMock()
+ )
+ )
+
+ assert batches == [[{"id": "1"}]]
+ assert sess.post.call_count == 2
+
+
+@patch("tenacity.nap.time.sleep")
+def test_request_reraises_retryable_after_persistent_408(_mock_sleep):
+ sess = MagicMock()
+ sess.post.return_value = _real_response(408, "Request Timeout")
+
+ with pytest.raises(ShopifyRetryableError):
+ list(
+ _make_paginated_shopify_request(
+ "https://example.invalid/graphql", sess, SHOPIFY_GRAPHQL_OBJECTS[ABANDONED_CHECKOUTS], MagicMock()
+ )
+ )
+
+ assert sess.post.call_count == 5
+
+
@patch("tenacity.nap.time.sleep")
def test_request_retries_connection_broken_mid_stream_then_succeeds(_mock_sleep):
# A connection dropped mid-response surfaces from `post` as ChunkedEncodingError; it's