Repository navigation
Add opt-in Connected Sheets support for BigQuery - #4
Closed
pragmabits wants to merge 1 commit into
Closed
pragmabits wants to merge 1 commit into
pragmabits wants to merge 1 commit into
Conversation
Expose BigQuery data sources through add_bigquery_data_source, refresh_data_source and get_data_source_data, all gated behind ENABLE_BIGQUERY_TOOLS so the bigquery.readonly scope is only requested when the feature is asked for and already-authorized tokens keep working. Data source sheets are not addressable in A1 notation, which is why get_data_source_data reads them through grid data, and find_in_spreadsheet now skips non-grid sheets instead of failing the entire search when one is present. The live suite accepts an authorized OAuth token in addition to a service account, and covers the new tools when GOOGLE_TEST_BIGQUERY_PROJECT is configured.
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.
Motivation
The Sheets API supports Connected Sheets, which links a spreadsheet to live BigQuery data. This adds three tools for it.
The scope problem, and why this is opt-in
Any data source request requires the
bigquery.readonlyOAuth scope. Adding it toSCOPESunconditionally would widen the scope set of every existing installation and force each user back through the consent flow, since a stored token no longer covers the requested scopes.So the scope is only requested when
ENABLE_BIGQUERY_TOOLS=1(or--enable-bigquery) is set, and the three tools are not even registered otherwise. Verified:ENABLE_BIGQUERY_TOOLS=1Someone who does not want the feature sees no change at all.
Tools
add_bigquery_data_source— connect a table or raw SQLrefresh_data_source— re-run one or all data sourcesget_data_source_data— read the resulting rowsFindings worth documenting regardless of this PR
Verified end to end against the real API:
DATA_SOURCEsheets are invisible to the values API.get_sheet_datafails on them withUnable to parse range. Reading requires grid data — this is whyget_data_source_dataexists rather than complicatingget_sheet_data.addDataSourcereply does not name the sheet it creates. It returns onlydataSourceId, so the sheet has to be located by that id afterwards, otherwise the caller cannot reach the data.addDataSourceandrefresh.Regression this feature would have exposed
find_in_spreadsheetwrapped its whole per-sheet loop in a singletry/except. Once a spreadsheet has aDATA_SOURCEsheet, the values call raises and the search returns an error, discarding matches already found in the other sheets. Reproduced against the real API, then fixed by skipping non-grid sheets.get_multiple_spreadsheet_summarywas checked too and already degrades correctly.Tests
Unit tests with fakes for configuration parsing, the registration gate, request construction and the missing-scope hint. The live suite gained a Connected Sheets case, skipped unless
GOOGLE_TEST_BIGQUERY_PROJECTis set; both workflows pass the variables through, so enabling live coverage is a matter of creating two secrets.The live bootstrap also learned to accept an already-authorized OAuth token, not just a service account — the README treats OAuth as a first-class auth method, but the live suite could not run with it. It never starts the interactive flow: a missing token skips.
Suite green on Python 3.10, 3.12 and 3.13.