Skip to content

fix(pyo3): default U2M scopes to ["sql","offline_access"] for the default Python client - #153

Merged
vikrantpuppala merged 1 commit into
mainfrom
fix/pyo3-u2m-default-scopes
Jun 10, 2026
Merged

vikrantpuppala merged 1 commit into
mainfrom
fix/pyo3-u2m-default-scopes

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

Summary

  • The pyo3 binding overrides the U2M client_id default to databricks-sql-python (to match the Thrift connector's OAuth app identity) but forwards scopes=None unchanged, so the kernel's intrinsic default of ["all-apis", "offline_access"] is applied. databricks-sql-python is only registered for sql (+ offline_access) on the Databricks IdP, so an out-of-the-box Session(auth_type="oauth-u2m") from Python fails the authorization request:

    access_denied — Scopes 'all-apis' are not assigned to the client databricks-sql-python
    
  • Fix: introduce PYSQL_OAUTH_SCOPES = ["sql", "offline_access"] next to PYSQL_OAUTH_CLIENT_ID and default scopes to it when the caller passed neither client_id nor scopes. Matches the Thrift connector's PYSQL_OAUTH_SCOPES in auth/auth.py, restoring use_kernel=True drop-in parity.

  • A caller-supplied client_id still gets scopes=None forwarded (custom clients may legitimately request all-apis). An explicit scopes is always honoured verbatim.

Test plan

  • Unit tests updated/added in pyo3/src/auth.rs:
    • u2m_defaults_client_id_and_scopes_to_python_connector — both defaults applied together.
    • u2m_explicit_client_id_overrides_default — custom client_id keeps scopes=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 warnings clean.
  • cargo test --lib --tests — 14 passed, including all 9 auth tests.
  • End-to-end against e2-dogfood.staging.cloud.databricks.com:
    • Before fix: sql.connect(auth_type="databricks-oauth", use_kernel=True) → access_denied from IdP.
    • After fix: same call (no oauth_scopes) opens a session, browser flow completes, SELECT current_user() returns the user.

This pull request and its description were written by Isaac.

…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>
@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Jun 10, 2026
Merged via the queue into main with commit 136fd86 Jun 10, 2026
19 checks passed
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 branch was previously deployed

1 inactive deployment
azure-prod — ca34e1a2 Deployed Jun 10, 2026 by vikrantpuppala via PyO3 build + test (Python 3.11) #119
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.

3 participants