: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(shopify): treat 402 Payment Required as non-retryable (#63714)
Tom Owers028ba8b25994
diff --git a/posthog/temporal/data_imports/sources/shopify/shopify.py b/posthog/temporal/data_imports/sources/shopify/shopify.pyindex c313d0a94f94..bc9e4beb7ad8 100644--- a/posthog/temporal/data_imports/sources/shopify/shopify.py+++ b/posthog/temporal/data_imports/sources/shopify/shopify.py@@ -49,6 +49,19 @@ SHOPIFY_ACCESS_TOKEN_AUTH_ERROR = (# The field name varies, so the match anchors on the stable leading phrase.SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR = "Access denied for"+# Shopify's Admin API returns 402 Payment Required when the store is frozen for an unpaid+# bill — the shop owner must settle their outstanding Shopify balance to unfreeze the store,+# so retrying the import cannot recover. `requests.raise_for_status` renders this as+# "402 Client Error: Payment Required for url: https://<store>.myshopify.com/...".+# `ShopifySource.get_non_retryable_errors` matches on the stable status text (not the+# per-store URL) to fail the job fast.+SHOPIFY_PAYMENT_REQUIRED_ERROR_MATCH = "402 Client Error: Payment Required"+SHOPIFY_PAYMENT_REQUIRED_ERROR_MESSAGE = (+ "Shopify returned 402 Payment Required — your Shopify store appears to be frozen due to "+ "an unpaid bill. Settle your outstanding balance in Shopify to unfreeze the store, then "+ "the import will resume."+)+@dataclasses.dataclassclass ShopifyResumeConfig:diff --git a/posthog/temporal/data_imports/sources/shopify/source.py b/posthog/temporal/data_imports/sources/shopify/source.pyindex f25410b36781..fbbc335f2b9c 100644--- a/posthog/temporal/data_imports/sources/shopify/source.py+++ b/posthog/temporal/data_imports/sources/shopify/source.py@@ -20,6 +20,8 @@ from posthog.temporal.data_imports.sources.shopify.settings import ENDPOINT_CONFfrom posthog.temporal.data_imports.sources.shopify.shopify import (SHOPIFY_ACCESS_TOKEN_AUTH_ERROR,SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR,+ SHOPIFY_PAYMENT_REQUIRED_ERROR_MATCH,+ SHOPIFY_PAYMENT_REQUIRED_ERROR_MESSAGE,ShopifyPermissionError,ShopifyResumeConfig,shopify_source,@@ -47,6 +49,9 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):"Your Shopify access token is missing the permissions required to read some of your data. ""Please reconnect your Shopify integration and grant the requested access scopes."),+ # 402 Payment Required from the Admin API — the store is frozen for an unpaid+ # bill. Retrying cannot recover; the shop owner must settle their Shopify balance.+ SHOPIFY_PAYMENT_REQUIRED_ERROR_MATCH: SHOPIFY_PAYMENT_REQUIRED_ERROR_MESSAGE,}@propertydiff --git a/posthog/temporal/data_imports/sources/shopify/tests/test_non_retryable_errors.py b/posthog/temporal/data_imports/sources/shopify/tests/test_non_retryable_errors.pyindex 8276028c8eb2..ce106b729bff 100644--- a/posthog/temporal/data_imports/sources/shopify/tests/test_non_retryable_errors.py+++ b/posthog/temporal/data_imports/sources/shopify/tests/test_non_retryable_errors.py@@ -1,8 +1,23 @@import pytest+import requests++from posthog.temporal.data_imports.sources.shopify.shopify import SHOPIFY_PAYMENT_REQUIRED_ERROR_MATCHfrom posthog.temporal.data_imports.sources.shopify.source import ShopifySource+def _http_error_message(status_code: int, reason: str) -> str:+ # Build the exact string requests.raise_for_status produces, so the test breaks if+ # the match substring ever drifts from the real message format.+ response = requests.models.Response()+ response.status_code = status_code+ response.reason = reason+ response.url = "https://msivuk-gs.myshopify.com/admin/api/2025-10/graphql.json"+ with pytest.raises(requests.HTTPError) as exc_info:+ response.raise_for_status()+ return str(exc_info.value)++@pytest.mark.parametrize("error_message",[@@ -17,6 +32,15 @@ def test_graphql_access_denied_is_non_retryable(error_message):)+def test_payment_required_is_non_retryable():+ error_message = _http_error_message(402, "Payment Required")+ assert SHOPIFY_PAYMENT_REQUIRED_ERROR_MATCH in error_message+ patterns = ShopifySource().get_non_retryable_errors()+ assert any(pattern in error_message for pattern in patterns), (+ f"402 Payment Required error '{error_message}' should match a non-retryable pattern"+ )++@pytest.mark.parametrize("error_message",[@@ -30,3 +54,20 @@ def test_transient_graphql_errors_stay_retryable(error_message):assert not any(pattern in error_message for pattern in patterns), (f"transient error '{error_message}' should remain retryable")+++ "status_code,reason",+ [+ (429, "Too Many Requests"),+ (500, "Internal Server Error"),+ (502, "Bad Gateway"),+ (503, "Service Unavailable"),+ ],+)+def test_transient_http_errors_stay_retryable(status_code, reason):+ error_message = _http_error_message(status_code, reason)+ patterns = ShopifySource().get_non_retryable_errors()+ assert not any(pattern in error_message for pattern in patterns), (+ f"transient error '{error_message}' should remain retryable"+ )