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(app_store_connect): say which role fixes a rejected table (#99688)

Tom Owers0e593ee7f421
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/source.py
index 014c1d64ff00..db440c8c87c3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/source.py
@@ -1,5 +1,7 @@
from typing import Optional, cast
+import structlog
+
from posthog.schema import (
DataWarehouseSourceCategory,
ExternalDataSourceType as SchemaExternalDataSourceType,
@@ -44,6 +46,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
)
from products.warehouse_sources.backend.types import ExternalDataSourceType
+logger = structlog.get_logger(__name__)
+
+_UNEXPECTED_PROBE_STATUS = "App Store Connect is not answering correctly right now. Wait a few minutes, then try again."
+
_MISSING_VENDOR_NUMBER = (
"Add your vendor number in the source settings to sync sales and subscription reports. "
"You can find it in App Store Connect under Payments and Financial Reports."
@@ -251,9 +257,12 @@ Leave **app IDs** blank to sync every app the key can read. To sync only some of
# reports what it can't reach, so don't block source creation on it.
return True, None
if status == 403:
- return False, "Your App Store Connect API key does not have permission to read this data."
+ return False, APP_STORE_CONNECT_READ_FORBIDDEN_ERROR
if status != 200:
- return False, f"App Store Connect returned status {status}"
+ # Apple answers a signed probe with 429 or a 5xx when it is busy. The status itself means
+ # nothing to the user, so keep it in the log and tell them what to do instead.
+ logger.warning("app_store_connect_credential_probe_unexpected_status", status=status)
+ return False, _UNEXPECTED_PROBE_STATUS
# Create and edit only: the per-schema call runs once per table in the picker, and each
# would list every app again.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect_source.py
index dd95f46f575d..554262493645 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect_source.py
@@ -172,6 +172,8 @@ class TestAppStoreConnectSource:
assert valid is expected_valid
assert (error is None) is expected_valid
+ # The message is read in the source wizard, where an HTTP status tells the user nothing.
+ assert status is None or error is None or str(status) not in error
def test_forbidden_is_accepted_at_source_create_but_not_per_schema(self) -> None:
source = AppStoreConnectSource()
@@ -182,8 +184,8 @@ class TestAppStoreConnectSource:
# A key whose role can't read `/v1/apps` is still a real key, so source creation must not fail.
assert (created, create_error) == (True, None)
- assert per_schema is False
- assert schema_error is not None
+ # Naming the roles that can read the table is the only way out of this one.
+ assert (per_schema, schema_error) == (False, APP_STORE_CONNECT_READ_FORBIDDEN_ERROR)
def test_an_unreadable_app_id_blocks_the_source_with_the_probe_message(self) -> None:
probe_message = "This API key cannot read these app IDs: 999. It can read: Acme (1234567890)."