fix: let BigQuery infer dataset location for view creation#5477
fix: let BigQuery infer dataset location for view creation#5477caohy1988 wants to merge 2 commits intogoogle:mainfrom
Conversation
The plugin previously passed a configured location (default "US") to bigquery.Client(location=...). This only affects query job routing, not table CRUD or the Storage Write API. When the dataset lives in a non-US region, view creation DDL queries silently fail with a location mismatch — data writes succeed but analytics views are missing. The fix auto-detects the dataset's actual location via get_dataset() during initialization and passes it explicitly to client.query() for view creation. Falls back to the configured location when dataset metadata cannot be resolved. Fixes google#5476 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @caohy1988, thank you for creating this PR! Before we can review your contribution, you'll need to sign the Contributor License Agreement (CLA). You can do so at https://cla.developers.google.com/. Once the CLA is signed, we will be able to proceed with the review. Thanks! |
| ) | ||
| try: | ||
| self.client.query(sql).result() | ||
| self.client.query(sql, location=self._resolved_location).result() |
There was a problem hiding this comment.
Is this needed?
Does it work if we always omit location, and bq client can resolve the location?
You're right — the explicit
So the simplest fix is just removing I'll simplify: remove |
Per review feedback: when bigquery.Client is created without a location parameter, client.query() sends no location field in the API request. BigQuery infers the job location from the dataset referenced in the DDL statement. This is simpler than auto-detecting via get_dataset(). The only production change from origin/main is removing location=self.location from the bigquery.Client() constructor call. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Fixes #5476
The plugin passed
location=self.location(default"US") tobigquery.Client(). This only affects query job routing — not table CRUD or the Storage Write API. When a dataset lives in a non-US region, view creation DDL queries silently fail with a location mismatch.Fix
Remove
location=self.locationfrom thebigquery.Client()constructor. When the client has no default location andclient.query(sql)is called without an explicitlocationparameter, the BQ API infers the job location from the dataset referenced in the DDL statement.Traced through the BQ Python client:
client.query(sql)—locationparam defaults toNone, falls back toself.locationwhich is alsoNone_to_query_request()— whenlocation is None, the"location"key is not included in the API requestCREATE OR REPLACE VIEWOne line of production code changed. Everything else is test updates.
What changes
Test plan
test_client_created_without_location— verifiesbigquery.Client()is called withoutlocationkwargtest_view_query_omits_location— verifiesclient.query()is called without explicitlocationtest_view_error_still_logged— view creation errors don't crash initialization🤖 Generated with Claude Code