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): tolerate a Gone status for an expired App Store Connect report day (#127055)

Tom Owersb63f46c62d19
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/settings.py
index cc2abf9dddb6..ed1897831c01 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/settings.py
@@ -95,7 +95,9 @@ class AppStoreConnectEndpointConfig:
report_frequency: str = "DAILY"
# Apple sometimes returns a misleading 400 instead of 404 for an empty report day. Endpoints that
# exhibit this quirk tolerate 400; `_fetch_report` classifies the response body before swallowing it.
- missing_report_status_codes: tuple[int, ...] = (404,)
+ # 410 shows up once a report date falls out of Apple's retention window — the oldest day in the
+ # lookback (SALES_REPORT_LOOKBACK_DAYS) reaches it on a cold start or a long-stalled sync.
+ missing_report_status_codes: tuple[int, ...] = (404, 410)
_REPORT_DATE_FIELD: IncrementalField = incremental_field("report_date", IncrementalFieldType.Date)
@@ -220,7 +222,7 @@ APP_STORE_CONNECT_ENDPOINTS: dict[str, AppStoreConnectEndpointConfig] = {
incremental_fields=[_REPORT_DATE_FIELD],
partition_key="report_date",
should_sync_default=False,
- missing_report_status_codes=(404, 400),
+ missing_report_status_codes=(404, 400, 410),
),
# Daily active subscription counts by state and territory.
"subscription_reports": AppStoreConnectEndpointConfig(
@@ -233,7 +235,7 @@ APP_STORE_CONNECT_ENDPOINTS: dict[str, AppStoreConnectEndpointConfig] = {
incremental_fields=[_REPORT_DATE_FIELD],
partition_key="report_date",
should_sync_default=False,
- missing_report_status_codes=(404, 400),
+ missing_report_status_codes=(404, 400, 410),
),
# Daily subscription lifecycle events (renewals, cancellations, upgrades).
"subscription_event_reports": AppStoreConnectEndpointConfig(
@@ -246,7 +248,7 @@ APP_STORE_CONNECT_ENDPOINTS: dict[str, AppStoreConnectEndpointConfig] = {
incremental_fields=[_REPORT_DATE_FIELD],
partition_key="report_date",
should_sync_default=False,
- missing_report_status_codes=(404, 400),
+ missing_report_status_codes=(404, 400, 410),
),
# Analytics Reports API streams: the behavioural data (sessions, downloads, installs
# and deletions, discovery, crashes, pre-orders, App Clips) that has no sales-report
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect.py b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect.py
index 0b9c7c09d906..77070936b52a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/app_store_connect/tests/test_app_store_connect.py
@@ -1894,6 +1894,25 @@ class TestSalesReports:
assert [(row["report_date"], row["units"]) for row in rows] == [(date(2026, 3, 4), 1)]
assert api.report_dates("SUBSCRIPTION") == ["2026-03-02", "2026-03-03", "2026-03-04"]
+ @time_machine.travel("2026-03-05 09:00:00", tick=False)
+ def test_sales_report_tolerates_an_expired_report_as_gone(self) -> None:
+ # Apple 410s a report date that has fallen out of its retention window instead of 404ing it —
+ # the oldest day in the lookback hits this on a cold start. It must not poison-pill the walk by
+ # raising on every retry of that day.
+ api = _FakeReportApi({"2026-03-04": "SKU\tUnits\nacme\t1\n"}, sales_status_code=410)
+
+ rows = _collect(
+ "sales_reports",
+ api,
+ _FakeManager(),
+ vendor_number="85234567",
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=date(2026, 3, 2),
+ )
+
+ assert [(row["report_date"], row["units"]) for row in rows] == [(date(2026, 3, 4), 1)]
+ assert api.report_dates("SALES") == ["2026-03-02", "2026-03-03", "2026-03-04"]
+
@time_machine.travel("2026-03-05 09:00:00", tick=False)
def test_unknown_vendor_number_fails_instead_of_completing_empty(self) -> None:
# Apple words a vendor number it doesn't know exactly like an empty subscription day, so a