GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@plamut plamut commented May 17, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@plamut
feat: detect obsolete BQ Storage extra at runtime
8e772e4
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label May 17, 2021
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label May 17, 2021
@plamut
Cover the changes with unit tests
af8ddec
@plamut
plamut marked this pull request as ready for review May 18, 2021 11:05
@plamut
plamut requested review from a team, stephaniewang526 and tswast and removed request for a team May 18, 2021 11:05
@plamut
Skip BQ Storage version tests if extra missing
24aea73
@plamut

plamut commented May 18, 2021

Copy link
Copy Markdown
Contributor Author

Will fix the coverage error son, one line not hit by the tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jimfulton
jimfulton self-requested a review May 18, 2021 14:06
jimfulton
jimfulton reviewed May 18, 2021
View reviewed changes

@jimfulton jimfulton left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread google/cloud/bigquery/client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/bigquery/dbapi/cursor.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/bigquery/_pandas_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/bigquery/magics/magics.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@plamut

plamut commented May 18, 2021

Copy link
Copy Markdown
Contributor Author

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. 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jimfulton

jimfulton commented May 18, 2021

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

plamut added 4 commits May 19, 2021 17:30
@plamut
Rename and improve _create_bqstorage_client()
cbb814c
The method is renamed to _ensure_bqstorage_client() and now performs
a check if BQ Storage dependency is recent enough.
@plamut
Remove BQ Storage check from dbapi.Cursor
89c0e1e
The check is now performed in dbapi.Connection, which is sufficient.
@plamut
Remove BQ Storage check in _pandas_helpers
4e5b31a
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.
@plamut
Simplify BQ Storage client factory in magics
fb3335a
Lean more heavily on client._ensure_bqstorage_client() to de-duplicate
logic.
@plamut

plamut commented May 19, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jimfulton
jimfulton approved these changes May 19, 2021
View reviewed changes

@jimfulton jimfulton left a comment

Copy link
Copy Markdown
Contributor

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plamut
Cover missing code lines with tests
5d01bdb
@plamut
plamut merged commit bd7dbda into googleapis:master May 20, 2021
@plamut
plamut deleted the iss-629 branch May 20, 2021 07:56
@release-please release-please Bot mentioned this pull request Jan 4, 2022
chore(main): release python-bigquery 1.27.1 #1097
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@stephaniewang526 stephaniewang526 Awaiting requested review from stephaniewang526
@tswast tswast Awaiting requested review from tswast
1 more reviewer
@jimfulton jimfulton jimfulton approved these changes
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.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

support google-cloud-bigquery-storage v1

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@plamut @jimfulton
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.