: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(warehouse): map BigQuery "ProjectId must be non-empty" to a clear error (#88963)
posthog[bot]a3cbde3e4a65
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.pyindex e6e171d1de31..fb55b4d8b7e9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py@@ -635,10 +635,14 @@ def validate_bigquery_credentials(try:with bigquery_client(project_id, location, private_key, private_key_id, client_email, token_uri) as bq:- bq.list_tables(+ tables = bq.list_tables(bq.dataset(dataset_id, project=dataset_project_id or project_id),retry=bigquery.DEFAULT_RETRY.with_timeout(5),)+ # `list_tables` returns a lazy iterator; the REST request runs only when a page is+ # consumed. Pull the first page inside the client context so identifier, dataset,+ # permission, and auth errors surface here instead of validating an unmade request.+ next(tables.pages, None)return True, Noneexcept Exception as e:# Mirror the stable substrings the sync-path classifier keys off, so the wizard names the@@ -649,7 +653,11 @@ def validate_bigquery_credentials(return False, BIGQUERY_INVALID_KEY_FILE_ERRORif "invalid_grant" in message:return False, BIGQUERY_CREDENTIALS_REJECTED_ERROR- if "Invalid project ID" in message or "Invalid dataset ID" in message:+ if (+ "Invalid project ID" in message+ or "Invalid dataset ID" in message+ or "ProjectId must be non-empty" in message+ ):return False, BIGQUERY_INVALID_IDENTIFIER_ERRORif "was not found in location" in message or "Not found: Dataset" in message:return False, BIGQUERY_DATASET_NOT_FOUND_ERROR@@ -1208,9 +1216,16 @@ class BigQueryImplementation(SQLSourceImplementation[BigQuerySourceConfig, bigquraise BigQueryDatasetNotFoundError(BIGQUERY_DATASET_NOT_FOUND_ERROR) from eexcept BadRequest as e:# A bad project/dataset ID surfaces as "400 Invalid project ID ..." / "Invalid dataset ID- # ...". Convert it to an actionable message; anything else is a genuine BadRequest we leave- # to propagate (including the transient job-internal-error the query retry predicate covers).- if "Invalid dataset ID" not in str(e) and "Invalid project ID" not in str(e):+ # ...", or as "400 ... ProjectId must be non-empty" when the value carries an underscore+ # (a character project IDs forbid). Convert it to an actionable message; anything else is a+ # genuine BadRequest we leave to propagate (including the transient job-internal-error the+ # query retry predicate covers).+ message = str(e)+ if (+ "Invalid dataset ID" not in message+ and "Invalid project ID" not in message+ and "ProjectId must be non-empty" not in message+ ):raisestructlog.get_logger().warning("BigQuery rejected an invalid project/dataset ID during schema discovery: %s", ediff --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.pyindex 3822c8d7a076..7d922cd6d596 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@@ -184,7 +184,9 @@ def test_bigquery_get_columns_raises_friendly_error_when_dataset_not_found():assert BIGQUERY_DATASET_NOT_FOUND_ERROR in BigQuerySource().get_non_retryable_errors()[email protected]("phrase", ['Invalid dataset ID "(default)"', 'Invalid project ID "bad id"'])+ "phrase", ['Invalid dataset ID "(default)"', 'Invalid project ID "bad id"', "ProjectId must be non-empty"]+)def test_bigquery_get_columns_raises_friendly_error_for_invalid_identifier(phrase):"""A syntactically invalid project/dataset ID surfaces as a raw 400 `BadRequest` from`client.query()`. Schema discovery must re-raise it with actionable wording instead of leaking@@ -1138,6 +1140,7 @@ def test_bigquery_validate_credentials_missing_fields_reports_actionable_message),(RefreshError("('invalid_grant: Invalid JWT Signature.', {})"), BIGQUERY_CREDENTIALS_REJECTED_ERROR, False),(BadRequest('Invalid dataset ID "(default)"'), BIGQUERY_INVALID_IDENTIFIER_ERROR, False),+ (BadRequest("400 ProjectId must be non-empty"), BIGQUERY_INVALID_IDENTIFIER_ERROR, False),(NotFound("404 Not found: Dataset my-project:my_dataset was not found in location US"),BIGQUERY_DATASET_NOT_FOUND_ERROR,@@ -1154,8 +1157,14 @@ def test_bigquery_validate_credentials_missing_fields_reports_actionable_messagedef test_bigquery_validate_credentials_maps_failures_to_actionable_messages(exception, expected_message, should_capture):+ # Validation consumes the first page of `list_tables`, and that page fetch is where the request+ # actually runs, so surface each failure from page consumption — the real request site. This+ # also guards the regression: an inert validation that never consumes a page would return+ # `(True, None)` and fail these assertions.+ bq = mock.MagicMock()+ bq.list_tables.return_value.pages.__next__.side_effect = exceptionclient_cm = mock.MagicMock()- client_cm.__enter__.side_effect = exception+ client_cm.__enter__.return_value = bqwith (mock.patch.object(bq_module, "bigquery_client", return_value=client_cm),