: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(bigquery): treat custom quota exceeded as non-retryable (#64279)
Tom Owers7ea252cf0b76
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.pyindex 5a94955b050a..acb79cbeea54 100644--- a/posthog/temporal/data_imports/sources/bigquery/source.py+++ b/posthog/temporal/data_imports/sources/bigquery/source.py@@ -92,6 +92,16 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):# proxy). Authentication can't succeed until the key file is fixed, so retrying just# hammers the endpoint and spams error tracking.BIGQUERY_TOKEN_RESPONSE_ERROR: "We couldn't authenticate with BigQuery — Google's OAuth token endpoint returned an unexpected response. Please re-upload your service account key file and verify its token_uri.",+ # Raised as a `Forbidden` (403, reason `quotaExceeded`) when the customer's BigQuery+ # project hits an administrator-configured custom cost control, e.g. "Custom quota+ # exceeded: Your usage exceeded the custom quota for QueryUsagePerDay, which is set by+ # your administrator.". This is a deliberate spend cap on the customer's GCP project,+ # not a transient limit — retrying within the sync's retry window can't recover it (the+ # cap resets on Google's daily schedule), so it just hammers the endpoint and spams+ # error tracking. We match the stable "Custom quota exceeded" wording, which is distinct+ # from transient rate-limit quota errors ("Quota exceeded: ..." / reason+ # `rateLimitExceeded`) that must stay retryable.+ "Custom quota exceeded": "Your BigQuery project hit a custom usage quota set by your administrator (for example QueryUsagePerDay). Raise the custom cost-control quota in Google Cloud, or reduce how much data you're syncing, then re-enable the source.",}def validate_credentials(diff --git a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.pyindex 45432f394c20..892997ce79ac 100644--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py@@ -552,6 +552,34 @@ def test_non_retryable_errors_match_federated_upstream_permission_denied(observeassert any(key in observed_error for key in non_retryable_errors)+ "observed_error",+ [+ # Administrator-set custom cost control on the customer's BigQuery project — surfaced as a+ # `Forbidden` whose str() is "403 Custom quota exceeded: ...".+ str(+ Forbidden(+ "Custom quota exceeded: Your usage exceeded the custom quota for QueryUsagePerDay, "+ "which is set by your administrator. For more information, see "+ "https://docs.cloud.google.com/bigquery/cost-controls.; reason: quotaExceeded"+ )+ ),+ # Per-user variant of the same custom cost control.+ str(+ Forbidden(+ "Custom quota exceeded: Your usage exceeded the custom quota for "+ "QueryUsagePerUserPerDay, which is set by your administrator.; reason: quotaExceeded"+ )+ ),+ ],+)+def test_non_retryable_errors_match_custom_quota_exceeded(observed_error):+ """An administrator-set custom cost control (e.g. QueryUsagePerDay) can't be recovered by+ retrying within the sync's window — the user must raise the quota or sync less data."""+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()+ assert any(key in observed_error for key in non_retryable_errors)++@pytest.mark.parametrize("other_error",[@@ -562,6 +590,11 @@ def test_non_retryable_errors_match_federated_upstream_permission_denied(observe# A federated-read failure that isn't a permission problem must stay retryable"Error while reading data, error message: Failed to fetch row from PostgreSQL server. ""Error: ERROR: connection to server timed out",+ # Transient rate-limit quota errors ("Quota exceeded" / `rateLimitExceeded`) are NOT the+ # administrator-set custom cost control and must stay retryable — the "Custom quota+ # exceeded" key must not catch them.+ "403 Quota exceeded: Your project exceeded quota for concurrent queries; reason: quotaExceeded",+ "403 Exceeded rate limits: too many concurrent queries for this project; reason: rateLimitExceeded",],)def test_non_retryable_errors_does_not_match_transient(other_error):