Skip to content

fix(gsheets): pass service_account_info via adapter_kwargs #38443

Open
piopy wants to merge 1 commit intoapache:masterfrom
piopy:fix/gsheets-service-account-creds
Open

fix(gsheets): pass service_account_info via adapter_kwargs #38443
piopy wants to merge 1 commit intoapache:masterfrom
piopy:fix/gsheets-service-account-creds

Conversation

@piopy
Copy link

@piopy piopy commented Mar 5, 2026

Fixes #38442

The existing assert_called_with assertions in test_validate_parameters_catalog and test_validate_parameters_catalog_and_credentials were updated to reflect the corrected call signature. The previous assertions were inadvertently testing the broken behavior.

SUMMARY

When using Google Sheets with service account authentication, the connection
fails because service_account_info is passed as a top-level keyword argument
to create_engine() instead of being nested under
connect_args → adapter_kwargs → gsheetsapi, as required by shillelagh.

This affects both update_params_from_encrypted_extra and validate_parameters.

Solution:

  • In update_params_from_encrypted_extra: wrap service_account_info and
    catalog inside connect_args.adapter_kwargs.gsheetsapi
  • In validate_parameters: use connect_args={"adapter_kwargs": {"gsheetsapi": {...}}}
    instead of top-level kwargs in create_engine()

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Uploaded in Issue 38442

TESTING INSTRUCTIONS

Verified manually with Superset 6.0.0 deployed via Docker Compose with a
Google service account JSON credential + pytest

ADDITIONAL INFORMATION

  • Has associated issue: [GSheets] Service account credentials and permission issue #38442
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

…params_from_encrypted_extra

Fixes apache#38442

The existing assert_called_with assertions in test_validate_parameters_catalog and test_validate_parameters_catalog_and_credentials were updated to reflect the corrected call signature. The previous assertions were inadvertently testing the broken behavior.
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Mar 5, 2026

Code Review Agent Run #6ffb40

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 8995062..8995062
    • superset/db_engine_specs/gsheets.py
    • tests/unit_tests/db_engine_specs/test_gsheets.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Google Sheets (Shillelagh) service account authentication by ensuring service_account_info is passed via connect_args -> adapter_kwargs -> gsheetsapi, matching Shillelagh’s expected adapter configuration.

Changes:

  • Update GSheetsEngineSpec.update_params_from_encrypted_extra to move service_account_info (and copy catalog) into connect_args.adapter_kwargs.gsheetsapi.
  • Update GSheetsEngineSpec.validate_parameters to pass credentials/subject via connect_args instead of top-level create_engine() kwargs.
  • Update unit tests to assert the corrected create_engine() call signature and add coverage for the new update_params_from_encrypted_extra behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
superset/db_engine_specs/gsheets.py Fixes engine creation/parameter shaping so Shillelagh receives service_account_info under connect_args.adapter_kwargs.gsheetsapi.
tests/unit_tests/db_engine_specs/test_gsheets.py Updates assertions for the corrected call signature and expands test coverage for parameter updates from encrypted extra.

Comment on lines 405 to 417
engine = create_engine(
"gsheets://",
service_account_info=encrypted_credentials,
subject=subject,
connect_args={
"adapter_kwargs": {
"gsheetsapi": {
"service_account_info": encrypted_credentials,
"subject": subject,
}
}
},
)
conn = engine.connect()
idx = 0
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate_parameters opens a SQLAlchemy connection via engine.connect() but never closes it. Since this method can return early (eg, missing name/url) or loop over multiple entries, this can leak connections/handles; wrap the connection in a context manager (or try/finally) and ensure the connection (and optionally the engine) is closed/disposed.

Copilot uses AI. Check for mistakes.
@bito-code-review
Copy link
Contributor

The suggestion to wrap the SQLAlchemy connection in a context manager (or use try/finally) is valid and improves the code by preventing potential connection leaks. The validate_parameters method opens a connection that may not be closed if the method returns early due to missing parameters or during iteration, which could exhaust database handles over time.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.97%. Comparing base (880cab5) to head (8995062).
⚠️ Report is 22 commits behind head on master.

Files with missing lines Patch % Lines
superset/db_engine_specs/gsheets.py 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #38443      +/-   ##
==========================================
+ Coverage   64.81%   64.97%   +0.15%     
==========================================
  Files        1815     2515     +700     
  Lines       71912   126743   +54831     
  Branches    22915    29230    +6315     
==========================================
+ Hits        46608    82345   +35737     
- Misses      25304    42969   +17665     
- Partials        0     1429    +1429     
Flag Coverage Δ
hive 41.63% <0.00%> (?)
mysql 63.40% <0.00%> (?)
postgres 63.47% <0.00%> (?)
presto 41.65% <0.00%> (?)
python 65.15% <0.00%> (?)
sqlite 63.09% <0.00%> (?)
unit 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:connect:googlesheets Related to Google Sheets size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GSheets] Service account credentials and permission issue

2 participants