Repository navigation
fix(bigquery): propagate universe_domain and guard custom endpoints in _ensure_bqstorage_client - #19199
Draft
chalmerlowe wants to merge 2 commits into
Draft
fix(bigquery): propagate universe_domain and guard custom endpoints in _ensure_bqstorage_client#19199chalmerlowe wants to merge 2 commits into
chalmerlowe wants to merge 2 commits into
Conversation
…n _ensure_bqstorage_client
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for propagating and validating universe domains across the BigQuery client and its sub-clients, specifically the BigQuery Storage client. Key changes include the addition of the _propagate_universe_to_client_options helper, raising UniverseMismatchError on mismatched credentials, exposing a universe_domain property on the Client, and implementing a fallback to REST with a warning when custom endpoints are configured without matching Storage endpoints. Additionally, a comprehensive test suite has been added to verify universe-domain conformance and routing behavior. No review comments were provided, so there is no feedback to address.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Context
When
bigquery.Clientis configured for a non-default universe such as a Trusted Partner Cloud (TPC) environment, or when a customapi_endpointorBIGQUERY_EMULATOR_HOSTis specified, universe configuration and routing can diverge in two places:Client._ensure_bqstorage_client()with an emptyClientOptions()object or{}mapping (whereuniverse_domainis unset) bypassed parentuniverse_domaininheritance, causing the child BigQuery Storage client to fall back to the default environment rather than inheritingself._universe_domain. Similarly, whenGOOGLE_CLOUD_UNIVERSE_DOMAINwas set in the environment andbigquery.Clientexplicitly selectedgoogleapis.com, leaving childuniverse_domainunset allowed the child client to pick up the environment variable instead of the parent client's universe.client_options.api_endpointonbigquery.Clientskipped_validate_universe()during initialization, and subsequent calls to_ensure_bqstorage_client()without an explicit BigQuery Storage endpoint still constructed a defaultBigQueryReadClientinstead of falling back to the configured BigQuery REST connection.Solution
universe_domainsafely (_helpers.py): Added_propagate_universe_to_client_options()to propagate the parentuniverse_domainontoNone,Mapping, andClientOptionsinputs whenever childuniverse_domainis unset and eitherparent_universeis non-default orGOOGLE_CLOUD_UNIVERSE_DOMAINdiffers fromparent_universe, using a shallow copy so caller-supplied objects and mappings are never mutated._helpers.py,client.py): UpdatedClient.__init__to resolveclient_universeunconditionally, expose a read-onlyClient.universe_domainproperty, and run_validate_universe()even whenclient_options.api_endpointis provided (as well as validating explicit childclient_optionsin_ensure_bqstorage_client()). Updated_validate_universe()to exemptNoneandAnonymousCredentialsand raisegoogle.api_core.universe.UniverseMismatchError(aValueErrorsubclass)._ensure_bqstorage_client()(client.py): Synchronizedself._has_custom_api_endpointwithself._connection.API_BASE_URLacrossclient_options.api_endpointandBIGQUERY_EMULATOR_HOST. When a custom BigQuery endpoint is active without an explicit BigQuery Storageapi_endpoint,_ensure_bqstorage_client()emits aUserWarningand returnsNoneso callers (to_dataframe,to_arrow, DB-API, and magics) fall back cleanly to the BigQuery REST transport.tests/unit/test_tpc_universe.py): Added client universe conformance tests, boundary and environment-precedence tests, and_ensure_bqstorage_client()routing, non-mutation, and REST fallback tests across GDU, TPC, and emulator configurations.Notes for Reviewers
UniverseMismatchErrorsubclassesValueError, preserving backward compatibility for callers catchingValueErroron mismatched credentials and universe settings.Nonefrom_ensure_bqstorage_client()matches the existing fallback contract used whengoogle-cloud-bigquery-storageis not installed, allowingRowIterator.to_arrow(),RowIterator.to_dataframe(), andbigquery.dbapi.connect()to read results overself._connectionwithout extra caller changes.