: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 GraphQL access-scope denials as non-retryable (#63722)
Tom Owersbc1ca965399f
diff --git a/posthog/temporal/data_imports/sources/shopify/shopify.py b/posthog/temporal/data_imports/sources/shopify/shopify.pyindex 8baf9ab81837..c313d0a94f94 100644--- a/posthog/temporal/data_imports/sources/shopify/shopify.py+++ b/posthog/temporal/data_imports/sources/shopify/shopify.py@@ -41,6 +41,14 @@ SHOPIFY_ACCESS_TOKEN_AUTH_ERROR = ("app was uninstalled. Please reconnect your Shopify integration.")+# Substring of the GraphQL error Shopify returns when the connected access token lacks the+# scope needed to read a field, e.g. "Access denied for fulfillmentOrders field." or+# "Access denied for paymentTerms field. Required access: `read_payment_terms` access scope."+# Retrying can't grant the missing scope — the user must reconnect with expanded permissions —+# so `ShopifySource.get_non_retryable_errors` matches this substring to fail the job fast.+# The field name varies, so the match anchors on the stable leading phrase.+SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR = "Access denied for"+@dataclasses.dataclassclass ShopifyResumeConfig:diff --git a/posthog/temporal/data_imports/sources/shopify/source.py b/posthog/temporal/data_imports/sources/shopify/source.pyindex d26d9f7149c1..f25410b36781 100644--- a/posthog/temporal/data_imports/sources/shopify/source.py+++ b/posthog/temporal/data_imports/sources/shopify/source.py@@ -19,6 +19,7 @@ from posthog.temporal.data_imports.sources.shopify.constants import SHOPIFY_GRAPfrom posthog.temporal.data_imports.sources.shopify.settings import ENDPOINT_CONFIGSfrom posthog.temporal.data_imports.sources.shopify.shopify import (SHOPIFY_ACCESS_TOKEN_AUTH_ERROR,+ SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR,ShopifyPermissionError,ShopifyResumeConfig,shopify_source,@@ -39,6 +40,13 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):# 4xx from Shopify's OAuth token endpoint — invalid/revoked app credentials.# Retrying cannot recover; the user must reconnect the integration.SHOPIFY_ACCESS_TOKEN_AUTH_ERROR: SHOPIFY_ACCESS_TOKEN_AUTH_ERROR,+ # GraphQL "Access denied for <field> field" — the access token is missing the+ # scope required to read this resource. The scope can't change on retry, so fail+ # fast and tell the user to reconnect with the required permissions.+ SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR: (+ "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."+ ),}@propertydiff --git a/posthog/temporal/data_imports/sources/shopify/tests/test_access_token.py b/posthog/temporal/data_imports/sources/shopify/tests/test_access_token.pyindex 35a4b3e6bb54..5ab06d963647 100644--- a/posthog/temporal/data_imports/sources/shopify/tests/test_access_token.py+++ b/posthog/temporal/data_imports/sources/shopify/tests/test_access_token.py@@ -53,3 +53,33 @@ def test_get_access_token_transient_stays_retryable(status_code):def test_get_access_token_success_returns_token():with _patched_token_call(_mock_response(200, ok=True, json_data={"access_token": "tok"})):assert _get_shopify_access_token("store", "client-id", "client-secret") == "tok"+++ "error_message",+ [+ "Shopify GraphQL error: Access denied for fulfillmentOrders field.",+ "Shopify GraphQL error: Access denied for paymentTerms field. Required access: `read_payment_terms` access scope.",+ "Shopify GraphQL error: Access denied for orders field.; Access denied for paymentTerms field.",+ ],+)+def test_graphql_access_denied_is_non_retryable(error_message):+ patterns = ShopifySource().get_non_retryable_errors()+ assert any(pattern in error_message for pattern in patterns), (+ f"GraphQL access-scope error '{error_message}' should match a non-retryable pattern"+ )+++ "error_message",+ [+ "Shopify: rate limit exceeded...",+ "Shopify: internal error from request 503 Service Unavailable",+ "Unexpected graphql response format in Shopify rows read. Keys: ['extensions']",+ ],+)+def test_transient_graphql_errors_stay_retryable(error_message):+ 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"+ )