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): stop retrying PII-restricted GraphQL errors (#103126)

Tom Owers4f7224b8b613
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 439def0908dd..b51cd8ecad64 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
@@ -121,6 +121,17 @@ SHOPIFY_STORE_NOT_FOUND_ERROR = (
# The field name varies, so the match anchors on the stable leading phrase.
SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR = "Access denied for"
+# Shopify's Protected Customer Data restriction — an app can only read PII fields (customer
+# names, addresses, emails, phone numbers) when the store's plan grants that access, regardless
+# of the token's granted scopes. The plan can't change on retry, so
+# `ShopifySource.get_non_retryable_errors` matches this substring to fail the job fast. The
+# object name and the docs URL vary per request, so the match anchors on the stable sentence
+# in between.
+SHOPIFY_GRAPHQL_PII_PLAN_RESTRICTED_ERROR = (
+ "Access to personally identifiable information (PII) like customer names, addresses, "
+ "emails, phone numbers is only available on Shopify, Advanced, and Plus plans"
+)
+
# 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
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 83de746f6378..da6f9e1a1862 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
@@ -40,6 +40,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.sh
SHOPIFY_ACCESS_TOKEN_UNSUPPORTED_GRANT_ERROR,
SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR,
SHOPIFY_GRAPHQL_NOT_FOUND_ERROR_MATCH,
+ SHOPIFY_GRAPHQL_PII_PLAN_RESTRICTED_ERROR,
SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MATCH,
SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MESSAGE,
SHOPIFY_MISSING_CREDENTIALS_ERROR,
@@ -110,6 +111,14 @@ 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."
),
+ # GraphQL "This app is not approved to access the <object> object" — the store's
+ # Shopify plan doesn't grant apps access to customer PII. No scope or reconnect can
+ # fix this; the merchant must upgrade their plan or stop syncing tables with PII.
+ SHOPIFY_GRAPHQL_PII_PLAN_RESTRICTED_ERROR: (
+ "Your Shopify plan doesn't allow apps to access customer personal data (PII) such as "
+ "names, addresses, emails, and phone numbers. Upgrade to the Shopify, Advanced, or Plus "
+ "plan, or turn off syncing the tables that include customer PII."
+ ),
# 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,
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 ddbb758a83bc..bf93d72f15f8 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
@@ -31,6 +31,26 @@ def test_graphql_access_denied_is_non_retryable(error_message):
)
+ "error_message",
+ [
+ "Shopify GraphQL error: This app is not approved to access the Customer object. Access to "
+ "personally identifiable information (PII) like customer names, addresses, emails, phone "
+ "numbers is only available on Shopify, Advanced, and Plus plans. Learn more: "
+ "https://admin.shopify.com/store/example-store/settings/apps/development/123456789/configuration",
+ "Shopify GraphQL error: This app is not approved to access the Order object. Access to "
+ "personally identifiable information (PII) like customer names, addresses, emails, phone "
+ "numbers is only available on Shopify, Advanced, and Plus plans. Learn more: "
+ "https://admin.shopify.com/store/example-store/settings/apps/development/123456789/configuration",
+ ],
+)
+def test_graphql_pii_plan_restricted_is_non_retryable(error_message):
+ patterns = ShopifySource().get_non_retryable_errors()
+ assert any(pattern in error_message for pattern in patterns), (
+ f"GraphQL PII-plan-restricted error '{error_message}' should match a non-retryable pattern"
+ )
+
+
@pytest.mark.parametrize(
"error_message",
[