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(bigquery): stop retrying queries blocked by a missing reservation (#120828)

Tom Owers8c1e12bbccfd
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
index c0cc331829dc..7e568a083f6c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
@@ -491,6 +491,15 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# has billing disabled (BigQuery sandbox mode), so any query job is rejected before it
# runs. There's nothing we can do but stop retrying until they enable billing.
"Billing has not been enabled for this project": "BigQuery billing is not enabled for your Google Cloud project. Enable billing in the Google Cloud console (https://console.cloud.google.com/billing), then resume this source.",
+ # Raised as a 400 BadRequest from `job.result()` (`_wait_for_job` in `bigquery.py`) when
+ # the queried region has neither on-demand pricing nor a flat-rate/capacity reservation
+ # configured for the customer's project, e.g. "Cannot run query: project does not have
+ # the reservation in the data region or no slots are configured; reason: invalid, ...".
+ # This is a billing/capacity setup problem on the customer's Google Cloud project, not a
+ # transient slot shortage — the same query fails identically on every retry until they
+ # enable on-demand pricing or create a reservation in that region. Matched on BigQuery's
+ # stable wording, not the volatile location or job id.
+ "project does not have the reservation in the data region or no slots are configured": "BigQuery couldn't run a query for this source because your Google Cloud project has neither on-demand pricing nor a flat-rate reservation configured for the queried region. Please enable on-demand pricing or create a BigQuery reservation for that region (https://console.cloud.google.com/bigquery/admin/reservations), then re-enable the source.",
# Raised from the shared `evolve_pyarrow_schema` in `pipelines/core/arrow_utils.py`
# when an integer column's source type was widened (e.g. `INT64` widened from a
# narrower numeric type) after the destination table was created with the narrower
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
index 7c2ae0671550..d830b43a68b1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -1200,6 +1200,21 @@ def test_non_retryable_errors_match_custom_quota_exceeded(observed_error):
assert any(key in observed_error for key in non_retryable_errors)
+def test_non_retryable_errors_match_no_reservation_or_slots_configured():
+ """A project with neither on-demand pricing nor a flat-rate reservation configured for the
+ queried region fails every query identically — retrying can't recover it, the user must
+ change their Google Cloud billing/capacity setup."""
+ observed_error = str(
+ BadRequest(
+ "Cannot run query: project does not have the reservation in the data region or no "
+ "slots are configured; reason: invalid, message: Cannot run query: project does not "
+ "have the reservation in the data region or no slots are configured\n\nLocation: US"
+ )
+ )
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ assert any(key in observed_error for key in non_retryable_errors)
+
+
def _run_has_duplicate_primary_keys(side_effect):
table = mock.MagicMock()
table.dataset_id = "dataset"