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(data-warehouse): read the apple ads account picker payload as oauth (#113172)

Tom Owers8bdf58de79a8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/source.py
index ccdc6fbfacb4..f6e842fdd912 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/source.py
@@ -310,11 +310,25 @@ Reporting tables use daily granularity, which Apple serves for the last 90 days
@staticmethod
def _normalize_job_inputs(job_inputs: dict) -> dict:
- """Make pre-auth-selector key-pair rows readable during a rolling deployment."""
+ """Wrap a flat payload in the auth branch the config expects.
+
+ Two callers send one: a key-pair row stored before the auth selector existed, and the
+ connect form's ad account picker, which posts the single field it holds rather than the
+ branch around it. Reading an integration id as key-pair material leaves the signing path
+ with no private key, so the id decides the branch.
+ """
if "auth_method" in job_inputs:
return job_inputs
normalized = dict(job_inputs)
+ integration_id = job_inputs.get("apple_ads_integration_id")
+ if integration_id:
+ normalized["auth_method"] = {
+ "selection": "oauth",
+ "apple_ads_integration_id": integration_id,
+ }
+ return normalized
+
normalized["auth_method"] = {
"selection": "key_pair",
"client_id": job_inputs.get("client_id"),
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads_source.py
index 4fe8eb59add7..ab21712cc431 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads_source.py
@@ -330,6 +330,30 @@ class TestAppleSearchAdsSource:
assert config.auth_method.private_key == "pem"
assert self.source.serialize_config(config)["private_key"] == "pem"
+ def test_the_ad_account_pickers_payload_authenticates_through_the_connected_account(self) -> None:
+ # The picker posts the one field it holds, with no auth branch around it. Read as key-pair
+ # material it carries no private key, so the listing signs an assertion from an empty PEM
+ # and the form answers "Could not sign the Apple Ads client secret" on a signed-in source.
+ integration = mock.MagicMock()
+ integration.kind = "apple-ads"
+ config = self.source.parse_config({"apple_ads_integration_id": "77"})
+
+ assert config.auth_method.selection == "oauth"
+ assert config.auth_method.apple_ads_integration_id == 77
+
+ with (
+ mock.patch.object(AppleSearchAdsSource, "get_oauth_integration", return_value=integration),
+ mock.patch(f"{SOURCE_MODULE}.apple_ads_access_token", return_value="bearer-1"),
+ mock.patch(f"{SOURCE_MODULE}.AppleSearchAdsClient") as mock_client,
+ mock.patch(f"{SOURCE_MODULE}.readable_ad_accounts") as mock_accounts,
+ ):
+ mock_accounts.return_value = [AppleAdAccount(id="1111111", name="Example Retail")]
+
+ accounts = self.source.get_credential_accounts(config, self.team_id)
+ assert mock_client.call_args.kwargs["token_provider"]() == "bearer-1"
+
+ assert [account.value for account in accounts] == ["1111111"]
+
def test_validate_credentials_rejects_a_grant_against_the_retired_api_version(self) -> None:
# Apple issues a service provider grant for the Platform API only. A v5-pinned source has
# to stay on its own key pair, so accepting one here would connect and then fail on sync.