Skip to content

fix(bigquery): ensure BigQuery client uses project from engine URI#41975

Open
Abhiiishek44 wants to merge 2 commits into
apache:masterfrom
Abhiiishek44:fix/bigquery-client-project
Open

fix(bigquery): ensure BigQuery client uses project from engine URI#41975
Abhiiishek44 wants to merge 2 commits into
apache:masterfrom
Abhiiishek44:fix/bigquery-client-project

Conversation

@Abhiiishek44

Copy link
Copy Markdown

SUMMARY

Fixes BigQuery metadata operations resolving datasets against the Application Default Credentials project instead of the project configured in the connection URI.

BigQueryEngineSpec._get_client previously created bigquery.Client without specifying a project. When the credentials project differed from the project in a connection such as bigquery://data-project, unqualified BigQuery table references were resolved against the credentials project and could return a dataset-not-found error.

This change:

  • Reads the project from engine.url.host.
  • Passes that project to bigquery.Client for both service-account credentials and Application Default Credentials.
  • Adds focused unit coverage for both authentication paths.

Fixes #41906

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable. This is a backend-only change.

TESTING INSTRUCTIONS

Automated tests:

python -m pytest \
  tests/unit_tests/db_engine_specs/test_bigquery.py \
  -k "get_client_uses_uri_project" \
  -vv

Result:

2 passed, 38 deselected

Code-quality checks:

python -m pre_commit run --files \
  superset/db_engine_specs/bigquery.py \
  tests/unit_tests/db_engine_specs/test_bigquery.py

Result:

All applicable hooks passed.

ADDITIONAL INFORMATION

@bito-code-review

bito-code-review Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #4f9425

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 1a21ce9..1a21ce9
    • superset/db_engine_specs/bigquery.py
    • tests/unit_tests/db_engine_specs/test_bigquery.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ 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

@dosubot dosubot Bot added the data:connect:googlebigquery Related to BigQuery label Jul 12, 2026
Comment thread superset/db_engine_specs/bigquery.py Outdated
"Could not import libraries needed to connect to BigQuery."
)

project = engine.url.host or None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: Add an explicit type annotation for the new local project variable to satisfy the type-hint requirement. [custom_rule]

Severity Level: Minor 🧹

Why it matters? ⭐

The new local variable project is clearly type-annotatable as str | None, but it is introduced without a type hint. This matches the custom rule requiring type hints on new or modified Python variables that can be annotated.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/db_engine_specs/bigquery.py
**Line:** 731:731
**Comment:**
	*Custom Rule: Add an explicit type annotation for the new local `project` variable to satisfy the type-hint requirement.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +439 to +449
credentials_info = {"project_id": "credential-project"}
credentials = mock.Mock()
engine = mock.MagicMock()
engine.url = make_url("bigquery://uri-project")
engine.dialect.credentials_info = credentials_info
create_credentials = mocker.patch(
"superset.db_engine_specs.bigquery.service_account.Credentials."
"from_service_account_info",
return_value=credentials,
)
client = mocker.patch("superset.db_engine_specs.bigquery.bigquery.Client")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: Add explicit type annotations for newly introduced local variables in this test to satisfy the type-hint requirement. [custom_rule]

Severity Level: Minor 🧹

Why it matters? ⭐

The added test introduces several local variables without type annotations, including mock objects and the credentials_info dict. This matches the type-hint rule for newly added Python code, so the suggestion is a real violation.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/db_engine_specs/test_bigquery.py
**Line:** 439:449
**Comment:**
	*Custom Rule: Add explicit type annotations for newly introduced local variables in this test to satisfy the type-hint requirement.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +463 to +471
credentials = mock.Mock()
engine = mock.MagicMock()
engine.url = make_url("bigquery://uri-project")
engine.dialect.credentials_info = None
get_default_credentials = mocker.patch(
"superset.db_engine_specs.bigquery.google.auth.default",
return_value=(credentials, "credential-project"),
)
client = mocker.patch("superset.db_engine_specs.bigquery.bigquery.Client")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: Add explicit type annotations for the new local variables in this test, including mocked objects and patched call handles. [custom_rule]

Severity Level: Minor 🧹

Why it matters? ⭐

The new test block assigns mock and patched objects to local variables without type hints. That is a direct match for the Python type-hint rule on newly introduced code.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/db_engine_specs/test_bigquery.py
**Line:** 463:471
**Comment:**
	*Custom Rule: Add explicit type annotations for the new local variables in this test, including mocked objects and patched call handles.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.95%. Comparing base (13c5a32) to head (003c03c).
⚠️ Report is 74 commits behind head on master.

Files with missing lines Patch % Lines
superset/db_engine_specs/bigquery.py 0.00% 3 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (13c5a32) and HEAD (003c03c). Click for more details.

HEAD has 46 uploads less than BASE
Flag BASE (13c5a32) HEAD (003c03c)
hive 6 1
python 38 2
presto 6 1
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41975      +/-   ##
==========================================
- Coverage   64.88%   55.95%   -8.93%     
==========================================
  Files        2742     2746       +4     
  Lines      153378   153674     +296     
  Branches    35168    35196      +28     
==========================================
- Hits        99516    85989   -13527     
- Misses      51958    66856   +14898     
+ Partials     1904      829    -1075     
Flag Coverage Δ
hive 39.06% <0.00%> (-0.02%) ⬇️
mysql ?
postgres ?
presto 41.04% <0.00%> (-0.02%) ⬇️
python 41.10% <0.00%> (-18.32%) ⬇️
sqlite ?
unit ?

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

☔ View full report in Codecov by Harness.
📢 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.

@rusackas

Copy link
Copy Markdown
Member

Looks like the fix only handles the bigquery://project URI form. get_schema_from_engine_params's docstring explicitly documents that bigquery:///project (triple-slash) puts the project in url.database with no host. There's already a test (test_get_default_catalog) exercising all three URI forms, indicating users on the triple-slash style would still hit the exact bug this PR intends to fix.

@rusackas rusackas self-requested a review July 14, 2026 17:24
@Abhiiishek44

Copy link
Copy Markdown
Author

Thanks. I’ll update _get_client() to fall back to url.database and add coverage for both URI forms.

@netlify

netlify Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 003c03c
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a56a1ab4e0c6a0008a075fb
😎 Deploy Preview https://deploy-preview-41975--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigQuery: table metadata resolves dataset against ADC project instead of connection URI project (cross-project Workload Identity broken in 6.x)

2 participants