: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): keep vendor token errors out of the setup message (#99965)
Tom Owers572ad85a9c7c
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.pyindex db568e49af21..439def0908dd 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@@ -46,8 +46,8 @@ PHASE_LATEST = "latest"# Raised when Shopify's OAuth token endpoint returns a 4xx that we can't attribute to a more# specific cause below. The app credentials are invalid or revoked, so re-entering them is the# only fix. `ShopifySource.get_non_retryable_errors` matches on this exact text to fail the job-# fast. The raised message also carries Shopify's own `error`/`error_description` (see-# `_oauth_error_detail`) so support can see what Shopify objected to.+# fast. Shopify's own `error`/`error_description` and the status code go to the log rather than+# into the message, which the wizard shows to the user.SHOPIFY_ACCESS_TOKEN_AUTH_ERROR = ("Shopify rejected your app credentials. Check the client ID and secret in your Shopify app and re-enter them here.")@@ -427,15 +427,6 @@ def _access_token_auth_error_message(error_code: str | None) -> str:return SHOPIFY_ACCESS_TOKEN_AUTH_ERROR-def _oauth_error_detail(error: _OAuthError, status_code: int) -> str:- """Shopify's raw error appended to the raised message so support can see what Shopify said."""- if error.code and error.description:- return f"Shopify {error.code}: {error.description}, HTTP {status_code}"- if error.code:- return f"Shopify {error.code}, HTTP {status_code}"- return f"HTTP {status_code}"--@retry(# A transient TLS/connection drop on the token endpoint (e.g. SSL EOF, proxy/egress hiccup,# connect/read timeout) surfaces from `post` as requests ConnectionError/Timeout — SSLError@@ -474,10 +465,11 @@ def _get_shopify_access_token(shopify_store_id: str, shopify_client_id: str, sho# is gone. Reconnecting the app can't fix that, so point the user at the store id# instead of telling them their credentials are bad.if access_res.status_code == 404:- raise Exception(f"{SHOPIFY_STORE_NOT_FOUND_ERROR} (HTTP 404)")+ raise Exception(SHOPIFY_STORE_NOT_FOUND_ERROR)# Any other 4xx means the app credentials are invalid/revoked — re-auth is the only fix,- # so surface a non-retryable message. Read Shopify's own `error`/`error_description` so- # the user gets the specific cause and support can see what Shopify rejected.+ # so surface a non-retryable message. Read Shopify's own `error`/`error_description` to+ # pick the message that names the cause, and log the raw values for support: the message+ # itself is what the wizard shows, so it carries no vendor code or status.if 400 <= access_res.status_code < 500 and access_res.status_code != 429:oauth_error = _parse_oauth_error(access_res)logger.warning(@@ -487,9 +479,7 @@ def _get_shopify_access_token(shopify_store_id: str, shopify_client_id: str, shoshopify_error=oauth_error.code,shopify_error_description=oauth_error.description,)- message = _access_token_auth_error_message(oauth_error.code)- detail = _oauth_error_detail(oauth_error, access_res.status_code)- raise Exception(f"{message} ({detail})")+ raise Exception(_access_token_auth_error_message(oauth_error.code))# 429 (rate limit) and 5xx (e.g. a 502 Bad Gateway from Shopify's edge) are transient —# retry locally with backoff instead of failing the import, mirroring the GraphQL path.raise ShopifyRetryableError(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_access_token.py b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_access_token.pyindex 2b40e2259a0f..f362ce745bca 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_access_token.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_access_token.py@@ -63,17 +63,18 @@ def test_get_access_token_4xx_is_non_retryable(status_code):],)def test_get_access_token_4xx_maps_shopify_error_code(error_code, expected_message):- # Shopify names the cause in the 4xx body. Each recognized code must surface its own- # message and carry Shopify's raw error/description so support can read what Shopify said.+ # Shopify names the cause in the 4xx body, so each recognized code must surface its own+ # message. The wizard shows this string, so Shopify's raw error, description and status+ # must stay out of it and live in the log instead.body = {"error": error_code, "error_description": "Shopify says so"}with _patched_token_call(_mock_response(400, ok=False, json_data=body)):with pytest.raises(Exception) as exc_info:_get_shopify_access_token("store", "client-id", "client-secret")error_message = str(exc_info.value)- assert expected_message in error_message- assert error_code in error_message- assert "Shopify says so" in error_message+ assert error_message == expected_message+ assert "Shopify says so" not in error_message+ assert "400" not in error_messagepatterns = ShopifySource().get_non_retryable_errors()assert any(pattern in error_message for pattern in patterns), (f"4xx token error '{error_message}' should match a non-retryable pattern"@@ -107,8 +108,7 @@ def test_get_access_token_4xx_html_body_falls_back_to_generic_message():_get_shopify_access_token("store", "client-id", "client-secret")error_message = str(exc_info.value)- assert SHOPIFY_ACCESS_TOKEN_AUTH_ERROR in error_message- assert "HTTP 400" in error_message+ assert error_message == SHOPIFY_ACCESS_TOKEN_AUTH_ERRORdef test_get_access_token_404_reports_missing_store():