: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
feat(warehouse-sources): connect Shopify with an Admin API access token (#92347)
Tom Owersaf1ea9eb18c3
diff --git a/products/warehouse_sources/backend/migrations/0158_migrate_shopify_job_inputs_to_auth_method.py b/products/warehouse_sources/backend/migrations/0158_migrate_shopify_job_inputs_to_auth_method.pynew file mode 100644index 000000000000..c25254189ca0--- /dev/null+++ b/products/warehouse_sources/backend/migrations/0158_migrate_shopify_job_inputs_to_auth_method.py@@ -0,0 +1,66 @@+from django.db import migrations+++def migrate_shopify_job_inputs(apps, schema_editor):+ ExternalDataSource = apps.get_model("warehouse_sources", "ExternalDataSource")++ for source in ExternalDataSource.objects.filter(source_type="Shopify"):+ job_inputs = source.job_inputs+ if not isinstance(job_inputs, dict):+ continue++ # Already migrated+ if "auth_method" in job_inputs:+ continue++ access_token = job_inputs.pop("shopify_access_token", None)+ client_id = job_inputs.pop("shopify_client_id", None)+ client_secret = job_inputs.pop("shopify_client_secret", None)++ if access_token:+ job_inputs["auth_method"] = {+ "selection": "access_token",+ "shopify_access_token": access_token,+ }+ else:+ job_inputs["auth_method"] = {+ "selection": "client_credentials",+ "shopify_client_id": client_id,+ "shopify_client_secret": client_secret,+ }++ source.job_inputs = job_inputs+ source.save(update_fields=["job_inputs"])+++def reverse_migrate_shopify_job_inputs(apps, schema_editor):+ ExternalDataSource = apps.get_model("warehouse_sources", "ExternalDataSource")++ for source in ExternalDataSource.objects.filter(source_type="Shopify"):+ job_inputs = source.job_inputs+ if not isinstance(job_inputs, dict):+ continue++ auth_method = job_inputs.get("auth_method")+ if not isinstance(auth_method, dict):+ continue++ if auth_method.get("selection") == "access_token":+ job_inputs["shopify_access_token"] = auth_method.get("shopify_access_token", "")+ else:+ job_inputs["shopify_client_id"] = auth_method.get("shopify_client_id", "")+ job_inputs["shopify_client_secret"] = auth_method.get("shopify_client_secret", "")++ job_inputs.pop("auth_method", None)+ source.job_inputs = job_inputs+ source.save(update_fields=["job_inputs"])+++class Migration(migrations.Migration):+ dependencies = [+ ("warehouse_sources", "0157_reset_plausible_page_breakdowns"),+ ]++ operations = [+ migrations.RunPython(migrate_shopify_job_inputs, reverse_migrate_shopify_job_inputs),+ ]diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txtindex 04fda7ca10df..3b0e145cbfcb 100644--- a/products/warehouse_sources/backend/migrations/max_migration.txt+++ b/products/warehouse_sources/backend/migrations/max_migration.txt@@ -1 +1 @@-0157_reset_plausible_page_breakdowns+0158_migrate_shopify_job_inputs_to_auth_methoddiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/shopify.py b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/shopify.pyindex 45472c59fcf1..f8d10d05c269 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/shopify.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/shopify.py@@ -1,11 +1,20 @@# This file is automatically generated from `SourceRegistry.get_all_sources()`# Do not edit manually - run `pnpm generate:source-configs` to regenerate.+from typing import Literal+from products.warehouse_sources.backend.temporal.data_imports.sources.common import config+class ShopifyAuthMethodConfig(config.Config):+ selection: Literal["client_credentials", "access_token"] = "client_credentials"+ shopify_client_id: str | None = None+ shopify_client_secret: str | None = None+ shopify_access_token: str | None = None++@config.configclass ShopifySourceConfig(config.Config):shopify_store_id: str- shopify_client_id: str- shopify_client_secret: str+ auth_method: ShopifyAuthMethodConfigdiff --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 a0faf9ec7762..b42d9b83cd99 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@@ -87,6 +87,23 @@ SHOPIFY_ACCESS_TOKEN_APP_NOT_INSTALLED_ERROR = ("Install the app on your store, then re-enter the client ID and secret here.")+# Shopify shows the app's client secret and the Admin API access token on adjacent screens, and+# both are opaque strings, so pasting the secret into the token field is an easy mistake. The+# secret carries a distinct prefix, so reject it here instead of sending it to the Admin API and+# reporting a generic 401 that points at the wrong field.+SHOPIFY_ACCESS_TOKEN_IS_APP_SECRET_ERROR = (+ "That looks like your app's client secret, not an Admin API access token. The access token "+ "starts with 'shpat_' and is shown on your app's API credentials page in your store admin."+)++# Raised when neither authentication method was filled in. The form marks every credential field+# optional because the user supplies one method or the other, so the "at least one method" rule+# cannot be enforced there and is enforced here instead.+SHOPIFY_MISSING_CREDENTIALS_ERROR = (+ "Shopify credentials are incomplete. Enter either an Admin API access token, or the client ID "+ "and secret of a Dev Dashboard app."+)+# Raised when the OAuth token endpoint returns 404 — there is no store at# `<store-id>.myshopify.com`, so the store id is wrong or the store no longer exists.# Reconnecting the app can't fix a bad store id, so this is surfaced separately from the@@ -474,6 +491,33 @@ def _get_shopify_access_token(shopify_store_id: str, shopify_client_id: str, shoreturn access_res.json()["access_token"]+# The prefix Shopify puts on an app's client secret, as opposed to the `shpat_` on an Admin API+# access token.+_SHOPIFY_APP_SECRET_PREFIX = "shpss_"+++def _resolve_access_token(+ shopify_store_id: str,+ shopify_client_id: str | None,+ shopify_client_secret: str | None,+ shopify_access_token: str | None,+) -> str:+ """The Admin API access token to authenticate with.++ A token the user supplied is used as it is. Shopify issues such a token for one store, so it+ works where `_get_shopify_access_token` cannot. That function uses the `client_credentials`+ grant, which Shopify allows only when the app and the store are in the same Shopify+ organization, and a merchant store often cannot join the organization that holds the app.+ """+ if shopify_access_token:+ if shopify_access_token.startswith(_SHOPIFY_APP_SECRET_PREFIX):+ raise Exception(SHOPIFY_ACCESS_TOKEN_IS_APP_SECRET_ERROR)+ return shopify_access_token+ if not shopify_client_id or not shopify_client_secret:+ raise Exception(SHOPIFY_MISSING_CREDENTIALS_ERROR)+ return _get_shopify_access_token(shopify_store_id, shopify_client_id, shopify_client_secret)++def _get_granted_scopes(store_id: str, sess: requests.Session) -> set[str] | None:"""The token's granted scope handles, or None on any failure — best-effort so a blip degradesthe query rather than failing the sync."""@@ -489,8 +533,8 @@ def _get_granted_scopes(store_id: str, sess: requests.Session) -> set[str] | Nondef shopify_source(shopify_store_id: str,- shopify_client_id: str,- shopify_client_secret: str,+ shopify_client_id: str | None,+ shopify_client_secret: str | None,graphql_object_name: str,db_incremental_field_last_value: Any | None,db_incremental_field_earliest_value: Any | None,@@ -498,15 +542,17 @@ def shopify_source(resumable_source_manager: ResumableSourceManager[ShopifyResumeConfig],api_version: str = SHOPIFY_API_VERSION_2026_07,should_use_incremental_field: bool = False,+ shopify_access_token: str | None = None,):store_id = normalize_store_id(shopify_store_id)api_url = SHOPIFY_API_URL.format(store_id, api_version)- shopify_access_token = _get_shopify_access_token(store_id, shopify_client_id, shopify_client_secret)+ access_token = _resolve_access_token(store_id, shopify_client_id, shopify_client_secret, shopify_access_token)schema_name = resolve_schema_name(graphql_object_name)def get_rows():sess = make_tracked_session(- headers={"X-Shopify-Access-Token": shopify_access_token, "Content-Type": "application/json"}+ headers={"X-Shopify-Access-Token": access_token, "Content-Type": "application/json"},+ redact_values=(access_token,),)graphql_object = SHOPIFY_GRAPHQL_OBJECTS.get(schema_name)if not graphql_object:@@ -626,7 +672,11 @@ def _format_graphql_errors(errors: Any) -> str:def _authenticated_session(- store_id: str, client_id: str, client_secret: str, api_version: str = SHOPIFY_API_VERSION_2026_07+ store_id: str,+ client_id: str | None,+ client_secret: str | None,+ api_version: str = SHOPIFY_API_VERSION_2026_07,+ access_token: str | None = None,) -> tuple[str, requests.Session]:"""Fetch an access token and return the GraphQL URL plus a session that carries it.@@ -635,8 +685,11 @@ def _authenticated_session(current default. Pre-creation callers omit it and get `default_version`."""api_url = SHOPIFY_API_URL.format(store_id, api_version)- access_token = _get_shopify_access_token(store_id, client_id, client_secret)- sess = make_tracked_session(headers={"Content-Type": "application/json", "X-Shopify-Access-Token": access_token})+ access_token = _resolve_access_token(store_id, client_id, client_secret, access_token)+ sess = make_tracked_session(+ headers={"Content-Type": "application/json", "X-Shopify-Access-Token": access_token},+ redact_values=(access_token,),+ )return api_url, sess@@ -656,10 +709,11 @@ def _probe_resource_permission(api_url: str, sess: requests.Session, resource: Sdef validate_credentials(shopify_store_id: str,- shopify_client_id: str,- shopify_client_secret: str,+ shopify_client_id: str | None,+ shopify_client_secret: str | None,resources: list[str] | None = None,api_version: str = SHOPIFY_API_VERSION_2026_07,+ shopify_access_token: str | None = None,) -> bool:"""Validate Shopify credentials.@@ -669,7 +723,9 @@ def validate_credentials(naming any whose scope is missing."""store_id = normalize_store_id(shopify_store_id)- api_url, sess = _authenticated_session(store_id, shopify_client_id, shopify_client_secret, api_version)+ api_url, sess = _authenticated_session(+ store_id, shopify_client_id, shopify_client_secret, api_version, shopify_access_token+ )# A valid token can always read the shop resource.try:@@ -699,16 +755,19 @@ def validate_credentials(def check_endpoint_permissions(shopify_store_id: str,- shopify_client_id: str,- shopify_client_secret: str,+ shopify_client_id: str | None,+ shopify_client_secret: str | None,endpoints: list[str],api_version: str = SHOPIFY_API_VERSION_2026_07,+ shopify_access_token: str | None = None,) -> dict[str, str | None]:"""Per-endpoint read-scope probe for the schema picker: {name: None} if reachable, else amessage naming the missing scope. A throttle/5xx/transport blip on one endpoint leaves thattable unknown rather than aborting the batch; only failing to obtain the access token raises."""store_id = normalize_store_id(shopify_store_id)- api_url, sess = _authenticated_session(store_id, shopify_client_id, shopify_client_secret, api_version)+ api_url, sess = _authenticated_session(+ store_id, shopify_client_id, shopify_client_secret, api_version, shopify_access_token+ )results: dict[str, str | None] = {}for name in endpoints:resource = SHOPIFY_GRAPHQL_OBJECTS.get(resolve_schema_name(name))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.pyindex 199b61b44b99..3e0736c71ac6 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@@ -7,6 +7,8 @@ from posthog.schema import (SourceConfig,SourceFieldInputConfig,SourceFieldInputConfigType,+ SourceFieldSelectConfig,+ SourceFieldSelectConfigOption,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource@@ -30,11 +32,13 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.shSHOPIFY_ACCESS_TOKEN_APP_NOT_INSTALLED_ERROR,SHOPIFY_ACCESS_TOKEN_AUTH_ERROR,SHOPIFY_ACCESS_TOKEN_INVALID_CLIENT_ERROR,+ SHOPIFY_ACCESS_TOKEN_IS_APP_SECRET_ERROR,SHOPIFY_ACCESS_TOKEN_SHOP_NOT_PERMITTED_ERROR,SHOPIFY_ACCESS_TOKEN_UNSUPPORTED_GRANT_ERROR,SHOPIFY_GRAPHQL_ACCESS_DENIED_ERROR,SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MATCH,SHOPIFY_GRAPHQL_UNAUTHORIZED_ERROR_MESSAGE,+ SHOPIFY_MISSING_CREDENTIALS_ERROR,SHOPIFY_PAYMENT_REQUIRED_ERROR_MATCH,SHOPIFY_PAYMENT_REQUIRED_ERROR_MESSAGE,SHOPIFY_STORE_NOT_FOUND_ERROR,@@ -83,6 +87,11 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):# 4xx `app_not_installed`: the credentials are valid but the app is not installed on# the store, so minting a token fails until the user installs it. Retrying cannot fix it.SHOPIFY_ACCESS_TOKEN_APP_NOT_INSTALLED_ERROR: SHOPIFY_ACCESS_TOKEN_APP_NOT_INSTALLED_ERROR,+ # The user pasted the app's client secret into the Admin API access token field. No+ # request is made, so this never reaches Shopify and retrying cannot change it.+ SHOPIFY_ACCESS_TOKEN_IS_APP_SECRET_ERROR: SHOPIFY_ACCESS_TOKEN_IS_APP_SECRET_ERROR,+ # Neither authentication method was filled in, so there is nothing to authenticate with.+ SHOPIFY_MISSING_CREDENTIALS_ERROR: SHOPIFY_MISSING_CREDENTIALS_ERROR,# 404 from the same endpoint — no store at this subdomain. Retrying cannot# recover; the user must correct the store id.SHOPIFY_STORE_NOT_FOUND_ERROR: SHOPIFY_STORE_NOT_FOUND_ERROR,@@ -122,9 +131,10 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):category=DataWarehouseSourceCategory.E_COMMERCE,iconPath="/static/services/shopify.png",caption=(- "Create a Shopify Dev Dashboard app, then enter its client ID and secret here to "- "pull your Shopify data into the PostHog Data warehouse. The docs walk through the "- "app setup steps."+ "Pull your Shopify store data into the PostHog Data warehouse. Pick how you want "+ "to connect. A Dev Dashboard app works when the app and the store belong to the "+ "same Shopify organization. When they cannot, use an Admin API access token from "+ "an app installed on the store. The docs walk through both options."),docsUrl="https://posthog.com/docs/data-warehouse/sources/shopify",fields=cast(@@ -142,21 +152,64 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):),secret=False,),- SourceFieldInputConfig(- name="shopify_client_id",- label="Client ID",- type=SourceFieldInputConfigType.TEXT,- required=True,- placeholder="client-id",- secret=False,- ),- SourceFieldInputConfig(- name="shopify_client_secret",- label="Secret",- type=SourceFieldInputConfigType.PASSWORD,+ SourceFieldSelectConfig(+ name="auth_method",+ label="Authentication method",required=True,- placeholder="client-secret",- secret=True,+ defaultValue="client_credentials",+ options=[+ SourceFieldSelectConfigOption(+ label="Client ID and secret",+ value="client_credentials",+ fields=cast(+ list[FieldType],+ [+ SourceFieldInputConfig(+ name="shopify_client_id",+ label="Client ID",+ type=SourceFieldInputConfigType.TEXT,+ required=False,+ placeholder="client-id",+ caption=(+ "From a Shopify Dev Dashboard app. The app and the "+ "store must belong to the same Shopify organization."+ ),+ secret=False,+ ),+ SourceFieldInputConfig(+ name="shopify_client_secret",+ label="Secret",+ type=SourceFieldInputConfigType.PASSWORD,+ required=False,+ placeholder="client-secret",+ secret=True,+ ),+ ],+ ),+ ),+ SourceFieldSelectConfigOption(+ label="Admin API access token",+ value="access_token",+ fields=cast(+ list[FieldType],+ [+ SourceFieldInputConfig(+ name="shopify_access_token",+ label="Admin API access token",+ type=SourceFieldInputConfigType.PASSWORD,+ required=False,+ placeholder="shpat_...",+ caption=(+ "Use this when your store cannot join the same "+ "Shopify organization as the app. Find it on the "+ "app's API credentials page in your store admin."+ ),+ secret=True,+ ),+ ],+ ),+ ),+ ],),],),@@ -176,10 +229,11 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):try:if validate_shopify_credentials(config.shopify_store_id,- config.shopify_client_id,- config.shopify_client_secret,+ config.auth_method.shopify_client_id,+ config.auth_method.shopify_client_secret,resources,self.resolve_api_version(api_version),+ shopify_access_token=config.auth_method.shopify_access_token,):return True, Nonereturn False, "Invalid Shopify credentials"@@ -193,10 +247,11 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):) -> dict[str, str | None]:return check_shopify_endpoint_permissions(config.shopify_store_id,- config.shopify_client_id,- config.shopify_client_secret,+ config.auth_method.shopify_client_id,+ config.auth_method.shopify_client_secret,endpoints,self.resolve_api_version(api_version),+ shopify_access_token=config.auth_method.shopify_access_token,)def get_schemas(@@ -237,8 +292,9 @@ class ShopifySource(ResumableSource[ShopifySourceConfig, ShopifyResumeConfig]):) -> SourceResponse:return shopify_source(shopify_store_id=config.shopify_store_id,- shopify_client_id=config.shopify_client_id,- shopify_client_secret=config.shopify_client_secret,+ shopify_client_id=config.auth_method.shopify_client_id,+ shopify_client_secret=config.auth_method.shopify_client_secret,+ shopify_access_token=config.auth_method.shopify_access_token,graphql_object_name=inputs.schema_name,api_version=self.resolve_api_version(inputs.api_version),should_use_incremental_field=inputs.should_use_incremental_field,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 617b27063a7e..2b40e2259a0f 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@@ -7,11 +7,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.shSHOPIFY_ACCESS_TOKEN_APP_NOT_INSTALLED_ERROR,SHOPIFY_ACCESS_TOKEN_AUTH_ERROR,SHOPIFY_ACCESS_TOKEN_INVALID_CLIENT_ERROR,+ SHOPIFY_ACCESS_TOKEN_IS_APP_SECRET_ERROR,SHOPIFY_ACCESS_TOKEN_SHOP_NOT_PERMITTED_ERROR,SHOPIFY_ACCESS_TOKEN_UNSUPPORTED_GRANT_ERROR,+ SHOPIFY_MISSING_CREDENTIALS_ERROR,SHOPIFY_STORE_NOT_FOUND_ERROR,ShopifyRetryableError,_get_shopify_access_token,+ _resolve_access_token,)from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.source import ShopifySource@@ -246,6 +249,55 @@ def test_payment_required_is_non_retryable(error_message):)+def test_resolve_access_token_uses_a_supplied_token_without_calling_shopify():+ # A supplied Admin API token belongs to one store, so it works where the client_credentials+ # grant cannot. Minting anyway would send the token endpoint credentials it does not have.+ with mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.shopify.shopify._get_shopify_access_token"+ ) as mint:+ assert _resolve_access_token("store", None, None, "shpat_supplied") == "shpat_supplied"+ mint.assert_not_called()+++def test_resolve_access_token_mints_when_only_client_credentials_are_set():+ with mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.shopify.shopify._get_shopify_access_token",+ return_value="minted",+ ) as mint:+ assert _resolve_access_token("store", "client-id", "client-secret", None) == "minted"+ mint.assert_called_once_with("store", "client-id", "client-secret")+++ "client_id,client_secret,access_token,expected_message",+ [+ # The client secret and the Admin API token sit on adjacent screens in Shopify and both+ # are opaque strings, so name the mix-up instead of sending the secret to the Admin API+ # and reporting the 401 it comes back with.+ ("", "", "shpss_looks_like_a_secret", SHOPIFY_ACCESS_TOKEN_IS_APP_SECRET_ERROR),+ (None, None, None, SHOPIFY_MISSING_CREDENTIALS_ERROR),+ # Half a client credentials pair cannot mint a token, and the form no longer marks+ # either half required, so this reaches the resolver rather than being caught earlier.+ ("client-id", None, None, SHOPIFY_MISSING_CREDENTIALS_ERROR),+ (None, "client-secret", None, SHOPIFY_MISSING_CREDENTIALS_ERROR),+ ],+)+def test_resolve_access_token_rejects_unusable_credentials(client_id, client_secret, access_token, expected_message):+ with mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.shopify.shopify._get_shopify_access_token"+ ) as mint:+ with pytest.raises(Exception) as exc_info:+ _resolve_access_token("store", client_id, client_secret, access_token)++ mint.assert_not_called()+ error_message = str(exc_info.value)+ assert expected_message in error_message+ patterns = ShopifySource().get_non_retryable_errors()+ assert any(pattern in error_message for pattern in patterns), (+ f"credential error '{error_message}' should match a non-retryable pattern"+ )++@pytest.mark.parametrize("error_message",[diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_api_version.py b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_api_version.pyindex 2bf319754f25..dfa7fea5ce57 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_api_version.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_api_version.py@@ -5,6 +5,7 @@ from unittest.mock import MagicMock, patchfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.shopify import (+ ShopifyAuthMethodConfig,ShopifySourceConfig,)from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.constants import (@@ -47,7 +48,10 @@ class TestApiVersionResolution:) -> None:source = ShopifySource()config = ShopifySourceConfig(- shopify_store_id="my-store", shopify_client_id="client-id", shopify_client_secret="secret"+ shopify_store_id="my-store",+ auth_method=ShopifyAuthMethodConfig(+ selection="client_credentials", shopify_client_id="client-id", shopify_client_secret="secret"+ ),)source.source_for_pipeline(config, MagicMock(spec=ResumableSourceManager), _make_inputs(pin))@@ -111,7 +115,10 @@ class TestNonSyncSurfacesUseResolvedPin:def test_validate_credentials_passes_resolved_pin(self, mock_validate: Any, pin: str | None, expected: str) -> None:mock_validate.return_value = Trueconfig = ShopifySourceConfig(- shopify_store_id="my-store", shopify_client_id="id", shopify_client_secret="secret"+ shopify_store_id="my-store",+ auth_method=ShopifyAuthMethodConfig(+ selection="client_credentials", shopify_client_id="id", shopify_client_secret="secret"+ ),)ShopifySource().validate_credentials(config, team_id=1, api_version=pin)@@ -131,7 +138,10 @@ class TestNonSyncSurfacesUseResolvedPin:def test_endpoint_permissions_pass_resolved_pin(self, mock_check: Any, pin: str | None, expected: str) -> None:mock_check.return_value = {}config = ShopifySourceConfig(- shopify_store_id="my-store", shopify_client_id="id", shopify_client_secret="secret"+ shopify_store_id="my-store",+ auth_method=ShopifyAuthMethodConfig(+ selection="client_credentials", shopify_client_id="id", shopify_client_secret="secret"+ ),)ShopifySource().get_endpoint_permissions(config, team_id=1, endpoints=[ORDERS], api_version=pin)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_validate_credentials.py b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_validate_credentials.pyindex f22c21f810be..6f84398c57ce 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_validate_credentials.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/shopify/tests/test_validate_credentials.py@@ -3,6 +3,7 @@ from typing import Anyfrom unittest import mockfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.shopify import (+ ShopifyAuthMethodConfig,ShopifySourceConfig,)from products.warehouse_sources.backend.temporal.data_imports.sources.shopify.source import ShopifySource@@ -40,7 +41,12 @@ def _post_returning(deny_if_query_contains: dict[str, dict[str, Any]]):def _config() -> ShopifySourceConfig:- return ShopifySourceConfig(shopify_store_id="my-store", shopify_client_id="cid", shopify_client_secret="secret")+ return ShopifySourceConfig(+ shopify_store_id="my-store",+ auth_method=ShopifyAuthMethodConfig(+ selection="client_credentials", shopify_client_id="cid", shopify_client_secret="secret"+ ),+ )def _patches(post):@@ -129,3 +135,21 @@ def test_endpoint_permissions_survive_a_throttle_on_one_table():assert result["orders"] is Noneassert result["products"] is Noneassert "read_product_listings" in (result["collections"] or "")+++def test_a_configured_access_token_authenticates_without_minting_one():+ # The store id and the access token reach `shopify.py` from different config fields, so a+ # token that is never threaded through would silently fall back to the minting path and fail+ # for the stores this option exists to serve.+ config = ShopifySourceConfig(+ shopify_store_id="my-store",+ auth_method=ShopifyAuthMethodConfig(selection="access_token", shopify_access_token="shpat_supplied"),+ )+ session = mock.MagicMock(post=mock.MagicMock(side_effect=_post_returning({})))++ with mock.patch(_TOKEN_PATH) as mint, mock.patch(_SESSION_PATH, return_value=session) as session_factory:+ valid, error = ShopifySource().validate_credentials(config, team_id=1)++ assert (valid, error) == (True, None)+ mint.assert_not_called()+ assert session_factory.call_args.kwargs["headers"]["X-Shopify-Access-Token"] == "shpat_supplied"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_generated_configs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_generated_configs.pyindex 234e05907dbe..ffad92a7a248 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_generated_configs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_generated_configs.py@@ -409,13 +409,39 @@ def test_stripe_config(config_dict, expected_auth_method_attrs):assert getattr(config.auth_method, attr) == expected-def test_shopify_config():- config = ShopifySourceConfig.from_dict(- {"shopify_store_id": "store_id", "shopify_client_id": "client_id", "shopify_client_secret": "client_secret"}- )+ "stored,expected_auth_method_attrs",+ [+ (+ {+ "shopify_store_id": "store_id",+ "auth_method": {+ "selection": "client_credentials",+ "shopify_client_id": "client_id",+ "shopify_client_secret": "client_secret",+ },+ },+ {"shopify_client_id": "client_id", "shopify_client_secret": "client_secret"},+ ),+ (+ {+ "shopify_store_id": "store_id",+ "auth_method": {"selection": "access_token", "shopify_access_token": "shpat_token"},+ },+ {"shopify_access_token": "shpat_token", "shopify_client_id": None},+ ),+ ],+)+def test_shopify_config(stored, expected_auth_method_attrs):+ # These are the two shapes the `auth_method` backfill writes for sources connected before the+ # select existed. `validate_dict` runs on update, so a rename on either side of that backfill+ # blocks editing every Shopify source that already exists.+ assert ShopifySourceConfig.validate_dict(stored) == (True, [])++ config = ShopifySourceConfig.from_dict(stored)assert config.shopify_store_id == "store_id"- assert config.shopify_client_id == "client_id"- assert config.shopify_client_secret == "client_secret"+ for attr, expected in expected_auth_method_attrs.items():+ assert getattr(config.auth_method, attr) == expecteddef test_temporal_config():