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): treat 401 from the Admin API as non-retryable (#73802)

Tom Owers00036d38ae53
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/shopify.py b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/shopify.py
index f776918af4ea..cabab05a22fb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/shopify.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/shopify.py
@@ -76,6 +76,18 @@ SHOPIFY_PAYMENT_REQUIRED_ERROR_MESSAGE = (
"the import will resume."
)
+# 401 from the Admin API GraphQL endpoint itself (as opposed to the OAuth token endpoint
+# above) — the token was accepted when minted but is no longer valid for the store, e.g. the
+# app was uninstalled or the token revoked mid-sync. Re-minting on retry can't fix that, so
+# `ShopifySource.get_non_retryable_errors` matches on the stable status text (not the
+# per-store URL) to fail the job fast.
+SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MATCH = "401 Client Error: Unauthorized"
+SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MESSAGE = (
+ "Shopify rejected the request with 401 Unauthorized — your Shopify access token is no "
+ "longer valid, likely because the app was uninstalled or access was revoked. Please "
+ "reconnect your Shopify integration."
+)
+
@dataclasses.dataclass
class ShopifyResumeConfig:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/source.py
index e43c2c3d3d14..df7d66984dc2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/source.py
@@ -32,6 +32,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.se
from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.shopify import (
SHOPIFY_ACCESS_TOKEN_AUTH_ERROR,
SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR,
+ SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MATCH,
+ SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MESSAGE,
SHOPIFY_PAYMENT_REQUIRED_ERROR_MATCH,
SHOPIFY_PAYMENT_REQUIRED_ERROR_MESSAGE,
SHOPIFY_STORE_NOT_FOUND_ERROR,
@@ -82,6 +84,10 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):
# 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,
+ # 401 from the Admin API GraphQL endpoint itself — the token was valid at mint
+ # time but Shopify now rejects it. Retrying cannot recover; the user must
+ # reconnect their integration.
+ SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MATCH: SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MESSAGE,
}
@property
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_non_retryable_errors.py b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_non_retryable_errors.py
index 746340fd4d37..5110d575d9f9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_non_retryable_errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_non_retryable_errors.py
@@ -3,6 +3,7 @@ import pytest
import requests
from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.shopify import (
+ SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MATCH,
SHOPIFY_PAYMENT_REQUIRED_ERROR_MATCH,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.source import ShopifySource
@@ -43,6 +44,15 @@ def test_payment_required_is_non_retryable():
)
+def test_graphql_unauthorized_is_non_retryable():
+ error_message = _http_error_message(401, "Unauthorized")
+ assert SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MATCH in error_message
+ patterns = ShopifySource().get_non_retryable_errors()
+ assert any(pattern in error_message for pattern in patterns), (
+ f"401 Unauthorized error '{error_message}' should match a non-retryable pattern"
+ )
+
+
@pytest.mark.parametrize(
"error_message",
[