Skip to content

fix(sqlalchemy-bigquery): resolve project before create_job_config - #19201

Open
julianxu-goog wants to merge 2 commits into
mainfrom
fix/sqlalchemy-bigquery-ambient-project-dataset
Open

julianxu-goog wants to merge 2 commits into
mainfrom
fix/sqlalchemy-bigquery-ambient-project-dataset

Conversation

@julianxu-goog

Copy link
Copy Markdown
Contributor

Resolve the BigQuery client's project before calling BigQueryDialect.create_job_config in create_connect_args:

  • Return early on user_supplied_client before calling create_job_config, avoiding an unnecessary google.auth.default() lookup when the URL includes a dataset.

  • Create the bigquery.Client and populate self.project_id / self.billing_project_id from client.project before calling self.create_job_config(provided_job_config) and assigning client.default_query_job_config. When connecting with bigquery:///dataset and explicit credentials (credentials_info, credentials_path, or credentials_base64), default_dataset now uses the explicit credentials' project rather than host ambient ADC (and combining bigquery:///dataset with billing_project_id no longer emits ConnectionProperty(key="dataset_project_id", value=None)).

  • Add unit tests covering explicit credentials (credentials_info, credentials_path, credentials_base64) with bigquery:///dataset, billing_project_id with local vs. remote datasets, user_supplied_client=true with a dataset, and direct create_job_config() fallback.

  • Ensure the tests and linter pass (nox -s lint, unit-3.14, unit-3.11, cover at 100% statement and branch coverage)

  • Code coverage does not decrease

Fixes internal issue b/581921313

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request refactors the create_connect_args method in sqlalchemy_bigquery/base.py to defer the creation of the default query job configuration until after the BigQuery client is initialized. This ensures that the project_id resolved from explicit credentials takes precedence over ambient Application Default Credentials (ADC) when constructing the job configuration. Additionally, several unit tests have been added to verify this behavior and prevent regressions. I have no further feedback to provide as the changes are well-implemented and thoroughly tested.

- Handle `user_supplied_client` in `BigQueryDialect.create_connect_args`
  before calling `create_job_config`, avoiding unnecessary ambient
  `google.auth.default()` calls when a dataset is present in the URL.
- Create `bigquery.Client` and resolve `self.project_id` and
  `self.billing_project_id` from `client.project` before constructing
  `default_query_job_config` so explicit credentials (`credentials_info`,
  `credentials_path`, `credentials_base64`) with `bigquery:///dataset`
  do not fall back to host ambient ADC or set `dataset_project_id=None`.
- Add unit tests covering explicit credentials with default datasets,
  `billing_project_id`, `user_supplied_client=true`, and direct
  `create_job_config()` fallback.

Fixes internal issue b/581921313
@julianxu-goog
julianxu-goog force-pushed the fix/sqlalchemy-bigquery-ambient-project-dataset branch from 80301b7 to 09dca11 Compare November 25, 2026 19:04
@julianxu-goog
julianxu-goog marked this pull request as ready for review November 25, 2026 20:02
@julianxu-goog
julianxu-goog requested review from a team as code owners November 25, 2026 20:02
@julianxu-goog
julianxu-goog requested review from sycai and tswast and removed request for a team November 25, 2026 20:02

@sycai sycai left a comment

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.

Overall LGTM. I have one style nit that needs to be addressed.

@julianxu-goog
julianxu-goog requested a review from sycai December 2, 2026 01:11

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants