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): stop disabling tables over recoverable errors (#111537)

Tom Owersf595d2f45279
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py
index f83c8c35a383..e9f0d98860a4 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py
@@ -607,14 +607,27 @@ def _property_rows(
) -> collections.abc.Iterator[list[dict[str, Any]]]:
session = google_search_console_session(config.google_search_console_integration_id, team_id)
- if resource_name == "sites":
- rows = [_site_to_dict(site) for site in list_sites(session)]
- else:
- sitemaps = list_sitemaps(session, normalize_site_url(config.site_url))
- if resource_name == "sitemaps":
- rows = [_sitemap_to_dict(sitemap) for sitemap in sitemaps]
+ try:
+ if resource_name == "sites":
+ rows = [_site_to_dict(site) for site in list_sites(session)]
else:
- rows = [row for sitemap in sitemaps for row in _sitemap_content_rows(sitemap)]
+ sitemaps = list_sitemaps(session, normalize_site_url(config.site_url))
+ if resource_name == "sitemaps":
+ rows = [_sitemap_to_dict(sitemap) for sitemap in sitemaps]
+ else:
+ rows = [row for sitemap in sitemaps for row in _sitemap_content_rows(sitemap)]
+ except requests.HTTPError as e:
+ # `list_sites` and `list_sitemaps` call `raise_for_status` directly, so a spent quota
+ # arrives here as a bare "403 Client Error". `get_non_retryable_errors` matches that
+ # string and the table is disabled, even though the quota refills on its own. Google
+ # answers a spent quota and a real permission failure with the same status, and only the
+ # body separates them, which is what `_is_quota_error` reads. A real permission failure
+ # still raises unchanged, so it keeps disabling the table as before.
+ if e.response is not None and _is_quota_error(e.response):
+ raise GoogleSearchConsoleQuotaExceededError(
+ f"Search Console quota exhausted while listing {resource_name}; the next sync picks it up (retryable)"
+ ) from e
+ raise
if rows:
yield rows
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py
index 28d8f6e7f26b..cb1c5fee069d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py
@@ -1158,3 +1158,36 @@ def test_no_base_schema_name_collides_with_a_search_type_suffix():
# of a shorter name, quietly querying the wrong dimensions.
for base_name in SEARCH_ANALYTICS_SCHEMAS:
assert split_schema_name(base_name) == (base_name, DEFAULT_SEARCH_TYPE)
+
+
[email protected]("resource_name", ["sites", "sitemaps"])
+ "body,expected_error,expected_match",
+ [
+ (_QUOTA_BODY, GoogleSearchConsoleQuotaExceededError, r"\(retryable\)"),
+ (_PERMISSION_BODY, requests.HTTPError, "403 Client Error"),
+ ],
+)
+def test_property_listing_separates_quota_from_permission_denial(
+ monkeypatch, resource_name, body, expected_error, expected_match
+):
+ # A spent quota and a denied permission share the 403, and only the body separates them.
+ # The quota case reaching `raise_for_status` is what disabled the table over a condition
+ # that refills on its own.
+ config = GoogleSearchConsoleSourceConfig(
+ site_url="https://example.com/",
+ google_search_console_integration_id=1,
+ )
+ session = mock.MagicMock()
+ session.get.return_value = _fake_response(403, body)
+ monkeypatch.setattr(gsc, "google_search_console_session", lambda *a, **kw: session)
+
+ response = google_search_console_source(
+ config=config,
+ resource_name=resource_name,
+ team_id=1,
+ resumable_source_manager=mock.MagicMock(),
+ )
+
+ with pytest.raises(expected_error, match=expected_match):
+ list(response.items()) # type: ignore[arg-type]
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py
index d6bbf240a0be..2ffa3da1e961 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py
@@ -828,14 +828,14 @@ _PROJECT_STATS_UNAVAILABLE_STATUSES = (
_NO_PROJECTS_AVAILABLE_DETAIL = "No projects available"
# Any other 400 from the stats-summary endpoint is a deterministic rejection of the request we
-# build (most often the requested window falling outside the org's plan retention), so retrying
-# replays it identically. Surface a credential-safe message the source classifies as non-retryable
-# (see `SentrySource.get_non_retryable_errors`) instead of burning retries on the raw HTTPError,
-# whose URL embeds the org slug. The wording never interpolates the org, URL, or response body.
+# build, so retrying replays it identically. Surface a credential-safe message the source
+# classifies as non-retryable (see `SentrySource.get_non_retryable_errors`) instead of burning
+# retries on the raw HTTPError, whose URL embeds the org slug. The wording never interpolates the
+# org, URL, or response body, and it names no cause: the reason Sentry gives is logged at the
+# raise site instead, because a guess here reads to a support engineer as a finding.
STATS_SUMMARY_REJECTED_MESSAGE = (
"Sentry rejected PostHog's request for your per-project usage stats (the "
- "organization_stats_summary table) with an HTTP 400. This usually means the requested date "
- "range is outside your Sentry plan's data retention. Remove that table from this source's "
+ "organization_stats_summary table) with an HTTP 400. Remove that table from this source's "
"selected tables, then re-enable the sync."
)
@@ -1019,7 +1019,11 @@ def _iter_organization_stats_summary_rows(
base_api_url,
_endpoint_path("organization_stats_summary", organization_slug=organization_slug),
headers,
- {"field": "sum(quantity)", "start": window.start, "end": window.end},
+ # `interval` defaults to 1h on this endpoint. Only `totals` is read below, so an
+ # hourly resolution over the retention window buys nothing and asks Sentry for about
+ # two thousand buckets per project. The sibling `organization_stats` request already
+ # sends a daily interval, so send the same one here.
+ {"field": "sum(quantity)", "interval": "1d", "start": window.start, "end": window.end},
)
except HTTPError as exc:
response = exc.response
@@ -1037,6 +1041,14 @@ def _iter_organization_stats_summary_rows(
organization_slug=organization_slug,
)
return
+ # Sentry's own reason is the one thing that identifies a rejection, and the curated
+ # message above deliberately drops it. Log it so the next rejection is diagnosed
+ # rather than guessed at. `detail` carries no credential and no org slug.
+ logger.warning(
+ "sentry_source.organization_stats_summary_rejected",
+ organization_slug=organization_slug,
+ detail=detail,
+ )
raise SentryStatsSummaryRejectedError(STATS_SUMMARY_REJECTED_MESSAGE) from exc
raise
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py
index 11f1439189f3..ae8584501d5d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py
@@ -1877,6 +1877,9 @@ class TestSentryCustomIteratorEndpoints:
assert seen_params[0] is not None
assert "statsPeriod" not in seen_params[0]
assert seen_params[0]["start"] and seen_params[0]["end"]
+ # Left unset, Sentry resolves this endpoint at 1h, which it rejects over a window this
+ # long. Only `totals` is read from the response, so a daily resolution loses nothing.
+ assert seen_params[0]["interval"] == "1d"
@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")
def test_stats_summary_skips_when_token_has_no_project_access(self, mock_request) -> None: