Repository navigation
fix(pyo3): default U2M scopes to ["sql","offline_access"] for the default Python client - #153
Merged
Merged
Conversation
…ault client
The pyo3 binding defaults the U2M `client_id` to `databricks-sql-python`
(matching the standalone Thrift connector's `PYSQL_OAUTH_CLIENT_ID`) but
forwarded `scopes=None` unchanged — so the kernel's intrinsic default of
`["all-apis", "offline_access"]` was applied. `databricks-sql-python` is
only registered for the `sql` scope on the Databricks IdP, so an
out-of-the-box `Session(auth_type="oauth-u2m")` from Python failed the
authorization request with:
access_denied — Scopes 'all-apis' are not assigned to the client
databricks-sql-python
Fix: add a `PYSQL_OAUTH_SCOPES` constant alongside `PYSQL_OAUTH_CLIENT_ID`
and default to it when the caller passed neither `client_id` nor `scopes`.
This keeps the two halves of the default consistent and matches
`PYSQL_OAUTH_SCOPES` in the Thrift connector's `auth/auth.py`, restoring
`use_kernel=True` drop-in parity.
A caller that supplies their own `client_id` still gets `scopes=None`
forwarded (their client may legitimately want `all-apis`). An explicit
`scopes` is always honoured verbatim.
Verified end-to-end against e2-dogfood.staging:
sql.connect(
server_hostname=...,
http_path=...,
auth_type="databricks-oauth",
use_kernel=True,
)
now opens a session and runs queries with no extra kwargs.
Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
gopalldb
approved these changes
Jun 10, 2026
vikrantpuppala
temporarily deployed
to
azure-prod
June 10, 2026 10:36 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
June 10, 2026 10:36 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
June 10, 2026 10:36 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
June 10, 2026 10:36 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
June 10, 2026 10:36 — with
GitHub Actions
Inactive
vikrantpuppala
enabled auto-merge
June 10, 2026 10:36
msrathore-db
approved these changes
Jun 10, 2026
vikrantpuppala
added a commit
that referenced
this pull request
Jun 10, 2026
The pyo3 U2M default-scopes fix (#153) merged into main after this PR was opened, so its NEXT_CHANGELOG.md entry needs to move into the v0.2.0 section of pyo3/CHANGELOG.md (the same release-cut surgery the parent commit did for the entries that existed at the time). - Move the "Fixed: U2M default scopes" entry from pyo3/NEXT_CHANGELOG.md → pyo3/CHANGELOG.md under [v0.2.0]. - Drop the "pyo3 surface unchanged from v0.1.2" claim from the v0.2.0 header — it no longer holds. - Empty pyo3/NEXT_CHANGELOG.md back to the template. No version-site changes (the wheel is already 0.2.0 in pyo3/Cargo.toml and pyo3/pyproject.toml from the parent commit, and the v0.2.0 release-date line stays as gopalldb cut it). Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
This was referenced Jun 10, 2026
This branch was previously deployed
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.
Summary
The pyo3 binding overrides the U2M
client_iddefault todatabricks-sql-python(to match the Thrift connector's OAuth app identity) but forwardsscopes=Noneunchanged, so the kernel's intrinsic default of["all-apis", "offline_access"]is applied.databricks-sql-pythonis only registered forsql(+offline_access) on the Databricks IdP, so an out-of-the-boxSession(auth_type="oauth-u2m")from Python fails the authorization request:Fix: introduce
PYSQL_OAUTH_SCOPES = ["sql", "offline_access"]next toPYSQL_OAUTH_CLIENT_IDand default scopes to it when the caller passed neitherclient_idnorscopes. Matches the Thrift connector'sPYSQL_OAUTH_SCOPESinauth/auth.py, restoringuse_kernel=Truedrop-in parity.A caller-supplied
client_idstill getsscopes=Noneforwarded (custom clients may legitimately requestall-apis). An explicitscopesis always honoured verbatim.Test plan
pyo3/src/auth.rs:u2m_defaults_client_id_and_scopes_to_python_connector— both defaults applied together.u2m_explicit_client_id_overrides_default— customclient_idkeepsscopes=None(kernel default wins).u2m_explicit_scopes_are_honoured_verbatim— caller-supplied scopes pass through unchanged with the default client.cargo +stable fmt --all+cargo clippy --all-targets -- -D warningsclean.cargo test --lib --tests— 14 passed, including all 9 auth tests.e2-dogfood.staging.cloud.databricks.com:sql.connect(auth_type="databricks-oauth", use_kernel=True)→access_deniedfrom IdP.oauth_scopes) opens a session, browser flow completes,SELECT current_user()returns the user.This pull request and its description were written by Isaac.