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-imports): stop missing App Store Connect vendor number retrying (#87983)

Tom Owers277b09f1811f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/app_store_connect.py b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/app_store_connect.py
index 0142f5752f04..70bd62ca86f1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/app_store_connect.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/app_store_connect.py
@@ -104,6 +104,14 @@ APP_STORE_CONNECT_ANALYTICS_INACTIVE_ERROR = (
"new request, which only an Admin key can create. Give the key the Admin role, then reconnect."
)
+# A sales or subscription report sync started without a vendor number. `/v1/salesReports` can't be
+# read without one, so every retry fails identically until the user adds it in the source settings.
+# `AppStoreConnectSource.get_non_retryable_errors` matches on this text to fail fast.
+APP_STORE_CONNECT_MISSING_VENDOR_NUMBER_ERROR = (
+ "Syncing App Store Connect sales reports needs your vendor number. "
+ "Add it in the source settings, then run the sync again."
+)
+
@frozen
class _AppleApiError:
@@ -783,10 +791,7 @@ def _get_sales_report(
db_incremental_field_last_value: Any,
) -> Iterator[list[dict[str, Any]]]:
if not vendor_number:
- raise ValueError(
- "Syncing App Store Connect sales reports needs your vendor number. "
- "Add it in the source settings, then run the sync again."
- )
+ raise ValueError(APP_STORE_CONNECT_MISSING_VENDOR_NUMBER_ERROR)
today = datetime.now(UTC).date()
end = today - timedelta(days=SALES_REPORT_END_OFFSET_DAYS)
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 1018a340ad18..658676cc6b0f 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
@@ -12,6 +12,7 @@ from posthog.schema import (
from products.warehouse_sources.backend.temporal.data_imports.sources.app_store_connect.app_store_connect import (
APP_STORE_CONNECT_ANALYTICS_CREATE_FORBIDDEN_ERROR,
APP_STORE_CONNECT_ANALYTICS_INACTIVE_ERROR,
+ APP_STORE_CONNECT_MISSING_VENDOR_NUMBER_ERROR,
APP_STORE_CONNECT_READ_FORBIDDEN_ERROR,
AppStoreConnectResumeConfig,
app_store_connect_source,
@@ -155,6 +156,9 @@ The analytics tables need a key with the Admin role. Apple lets only an Admin ke
APP_STORE_CONNECT_READ_FORBIDDEN_ERROR: APP_STORE_CONNECT_READ_FORBIDDEN_ERROR,
# Any 403 that didn't come through the custom raises still fails fast with the read message.
"403 Client Error: Forbidden for url: https://api.appstoreconnect.apple.com": APP_STORE_CONNECT_READ_FORBIDDEN_ERROR,
+ # A report sync selected without a vendor number can never read `/v1/salesReports`, so fail
+ # fast instead of retrying the activity's whole budget until the user adds the number.
+ APP_STORE_CONNECT_MISSING_VENDOR_NUMBER_ERROR: APP_STORE_CONNECT_MISSING_VENDOR_NUMBER_ERROR,
}
def get_retryable_errors(self) -> set[str]:
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 87b43156b266..e0c9d9ec8b46 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
@@ -14,6 +14,7 @@ from posthog.schema import (
from products.warehouse_sources.backend.temporal.data_imports.sources.app_store_connect.app_store_connect import (
APP_STORE_CONNECT_ANALYTICS_CREATE_FORBIDDEN_ERROR,
APP_STORE_CONNECT_ANALYTICS_INACTIVE_ERROR,
+ APP_STORE_CONNECT_MISSING_VENDOR_NUMBER_ERROR,
APP_STORE_CONNECT_READ_FORBIDDEN_ERROR,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.app_store_connect.settings import (
@@ -192,6 +193,13 @@ class TestAppStoreConnectSource:
assert error is not None and "vendor number" in error
mocked.assert_not_called()
+ def test_missing_vendor_number_is_non_retryable(self) -> None:
+ # A report sync raises this ValueError when no vendor number is set. It can never succeed on
+ # retry, so the source must classify it non-retryable rather than burn the activity's budget.
+ friendly = _resolve_friendly_error(APP_STORE_CONNECT_MISSING_VENDOR_NUMBER_ERROR)
+
+ assert friendly is not None
+
def test_auth_and_permission_failures_are_non_retryable(self) -> None:
errors = cast(dict[str, Any], AppStoreConnectSource().get_non_retryable_errors())