GeezerVison is showing github.com — feat: detect obsolete BQ Storage extra at runtime by plamut · Pull Request #666 · googleapis/python-bigquery
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Conversation
plamut
commented
May 17, 2021
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Closes #629.
This PR adds logic to detect obsolete versions of BQ Storage extra and emit a warning or raise an error where applicable.
Traced all BQ Storage-related code and call paths and I think the changes here cover them all. As a bonus, we get a graceful fallback to tabledata.list in most cases (a warning is emitted instead of raising an error).
- Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
- Ensure the tests and linter pass
- Code coverage does not decrease (if any source code was changed)
- Appropriate docs were updated (if necessary)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Will fix the coverage error son, one line not hit by the tests.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can be a little DRYer if we reuse _create_bqstorage_client more after adding some arguments to it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I think we can be a little DRYer if we reuse _create_bqstorage_client more after adding some arguments to it.
Sounds reasonable, I'll probably give it a shot. 👍
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I'm proposing that _create_bqstorage_client becomes something like:
def _create_bqstorage_client(self, bqstorage_client=None, client_info=None, client_options=None):
"""Create a BigQuery Storage API client using this client's credentials.
If a client cannot be created due to missing dependencies, raise a
warning and return ``None``.
Returns:
Optional[google.cloud.bigquery_storage.BigQueryReadClient]:
A BigQuery Storage API client.
"""
try:
from google.cloud import bigquery_storage
except ImportError:
warnings.warn(
"Cannot create BigQuery Storage client, the dependency "
"google-cloud-bigquery-storage is not installed."
)
return None
try:
_verify_bq_storage_version()
except LegacyBigQueryStorageError as exc:
warnings.warn(str(exc))
return None
if bqstorage_client is None:
bqstorage_client = bigquery_storage.BigQueryReadClient(
credentials=self._credentials,
client_info=client_info,
client_options=client_options,
)
return bqstorage_client
and maybe gets renamed :) and that it's called even when the caller is given a client.
If the library is out of date, the caller will end up with None even if given a value.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The method is renamed to _ensure_bqstorage_client() and now performs
a check if BQ Storage dependency is recent enough.
The check is now performed in dbapi.Connection, which is sufficient.
The methods in higher layers already do the same check before
a BQ Storage client instance is passed to
_pandas_helpers._download_table_bqstorage() helper.
Lean more heavily on client._ensure_bqstorage_client() to de-duplicate
logic.
plamut
commented
May 19, 2021
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
I checked the call chains and if I didn't miss anything, the only place left where a bad BQ Storage client could leak down is dbapi.Connection, which I sealed. Some of the lower-level checks turned out to be redundant, thus removed them:
- In
dbapi.Cursor._bqstorage_fetch()
- In
_pandas_helpers._download_table_bqstorage()
Refactored Client._make_bqstorage_client as suggested and de-duplicated logic in magics and dbapi.
Apart from the client's factory, the other central place where we check if BQ Storage client is compatible is table._validate_bqstorage() (and issues a warning if it isn't). The top level table methods use this check and set bqstorage_client to None, if necessary, before sending it down the call chain to lower level utility functions.
Edit: Will fix the two coverage misses tomorrow.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
tswast
Awaiting requested review from tswast
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
api: bigquery
Issues related to the googleapis/python-bigquery API.
cla: yes
This human has signed the Contributor License Agreement.
Milestone
No milestone
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.
|