Repository navigation
feat(database): add databricks oauth support - #41421
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41421 +/- ##
==========================================
- Coverage 64.52% 64.33% -0.20%
==========================================
Files 2664 2670 +6
Lines 146223 147317 +1094
Branches 33733 33880 +147
==========================================
+ Hits 94351 94770 +419
- Misses 50156 50815 +659
- Partials 1716 1732 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review Agent Run #0cb4e7
Actionable Suggestions - 1
-
docs/user_docs_versioned_docs/version-6.0.0/configuration/databases.mdx - 1
- Missing account_id placeholder substitution · Line 545-548
Additional Suggestions - 5
-
docs/user_docs_versioned_docs/version-6.0.0/configuration/databases.mdx - 1
-
Azure token_request_uri placeholder not substituted · Line 547-548The Azure entry in `_oauth2_endpoints` (`databricks.py:293-294`) has a `{}` placeholder in `token_request_uri` (`https://login.microsoftonline.com/{}/oauth2/v2.0/token`). Unlike `authorization_request_uri` where the code in `get_oauth2_authorization_uri` can override it, the `token_request_uri` is set in `get_oauth2_config` (base.py:745-747) from the class attribute which is empty (""), then never updated. Additionally, `get_oauth2_token` (databricks.py:605-614) only provides a fallback for missing token_request_uri using the AWS endpoint — it never extracts a per-provider tenant_id. The documentation at line 547 only flags `authorization_request_uri` as needing override, omitting `token_request_uri`, so users will configure and still fail silently.
-
-
tests/unit_tests/db_engine_specs/test_databricks.py - 2
-
Duplicated fixture definitions · Line 418-432The `oauth2_config_python` fixture (lines 418-432) is functionally identical to `oauth2_config_native` (lines 402-416) — both return the same dictionary. This duplication adds maintenance burden and divergence risk if one needs to change.
-
Semantic test duplication · Line 667-701This test is semantically duplicated from `test_get_oauth2_fresh_token_native` (lines 630-664). Both tests use identical fixtures (the `request_content_type: "json"` configs are structurally identical), call the same inherited method, and assert identical expectations. Since neither `DatabricksNativeEngineSpec` nor `DatabricksPythonConnectorEngineSpec` overrides `get_oauth2_fresh_token()`, testing them separately provides no additional coverage. The duplication creates maintenance risk — any future change must be applied twice, risking divergence.
-
-
superset/db_engine_specs/databricks.py - 2
-
Duplicate import across diff · Line 575-575The `from typing import cast` import appears 4 times (lines 575, 603, 856, 884) — twice in each child class. Consolidating the methods into the parent class will eliminate 3 of these. The remaining one should be moved to module-level imports.
-
Docstring Missing Accepted Values · Line 310-326The `_detect_cloud_provider` method accepts 'cloud_provider' from extra configuration but only validates against known providers after lowercasing. Consider documenting accepted values and what happens with invalid values.
-
Filtered by Review Rules
Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
-
superset/db_engine_specs/databricks.py - 2
- Semantic duplication across classes · Line 557-587
- Semantic duplication across classes · Line 589-616
-
tests/unit_tests/db_engine_specs/test_databricks.py - 1
- Missing pytest.fixture decorator · Line 402-432
Review Details
-
Files reviewed - 4 · Commit Range:
dafe036..47b7e01- docs/user_docs_versioned_docs/version-6.0.0/configuration/databases.mdx
- superset/db_engine_specs/databricks.py
- tests/unit_tests/db_engine_specs/test_databricks.py
- tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.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 [email protected].
Documentation & Help
Code Review Agent Run #71d2acActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run #909191Actionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run #6fa03dActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
get_oauth2_token clobbered the config's already-resolved token_request_uri
with the AWS template that still contained an unsubstituted account-id
placeholder, so the token exchange POSTed to .../accounts/{}/v1/token. Only
fall back to the AWS endpoint when no token_request_uri is configured.
Co-authored-by: fabian_zse <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…uth fixtures Co-Authored-By: Claude Opus 4.8 <[email protected]>
…figured URIs
The per-cloud OAuth2 endpoint templates carry a `{}` placeholder for the
Databricks account id (or Azure tenant id) that was never substituted, so
auto-detected authorize/token URLs were emitted as `.../accounts/{}/v1/...`.
The authorization-URI methods also unconditionally overwrote a fully-resolved
`authorization_request_uri` supplied via DATABASE_OAUTH2_CLIENTS.
- Add `_resolve_oauth2_endpoint`: substitutes `account_id`/`tenant_id` from the
database extra into the template, or raises OAuth2Error when absent instead of
issuing a request to an unresolved endpoint.
- Preserve a configured `authorization_request_uri`; only auto-detect/resolve
when none is set.
- `get_oauth2_token` has no database context to auto-detect, so fail fast on a
missing `token_request_uri` rather than POST to `.../{}/v1/token`.
- Cover auto-detect/resolve, preserve-configured, and fail-fast paths for both
the native and Python-connector specs; document `account_id`/`tenant_id`.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
The multi-cloud OAuth2 URI tests passed a config with a fully-resolved authorization_request_uri, which the engine spec now preserves. Drop the URI for the Azure/GCP detection cases (and give those mock databases an account_id/tenant_id) so the per-provider endpoint is actually resolved. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
The authorization endpoint auto-resolves from the hostname, but the token exchange has no database context, so token_request_uri must be supplied for the auto-detected flow. Docs implied both endpoints auto-detect. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The only uncovered branch in `_detect_cloud_provider`: an unrecognized explicit `cloud_provider` should be ignored and detection should fall back to hostname sniffing rather than returning the bad value. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…kspace host
Addresses review feedback on the Databricks OAuth2 flow:
- `oauth2_exception` was set to `OAuth2RedirectError` (Superset's own redirect
signal, also the base default), so `needs_oauth2()` never matched a real
Databricks token failure and the dance never auto-started. The driver has no
dedicated auth exception, so detect auth failures from the error message
instead (mirrors `GSheetsEngineSpec.needs_oauth2`).
- The per-cloud endpoint templates pointed Azure at Entra ID directly
(`login.microsoftonline.com`) and required `account_id`/`tenant_id`
substitution. Databricks fronts the U2M flow on every workspace at
`https://<host>/oidc/v1/{authorize,token}` across AWS/Azure/GCP, so the
authorization endpoint now derives from the workspace host with no account
identifier. The token endpoint still requires explicit config (no DB context
at exchange time); the error and docs now point at the workspace-host URL.
Shared OAuth logic is consolidated onto `DatabricksDynamicBaseEngineSpec`,
removing the duplicated overrides in both engine specs.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
9774116 to
563edfd
Compare
There was a problem hiding this comment.
Code Review Agent Run #7d833f
Actionable Suggestions - 1
-
tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py - 1
- Wrong mock patch path · Line 88-93
Filtered by Review Rules
Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
-
tests/unit_tests/db_engine_specs/test_databricks.py - 5
- Test assertion mismatch · Line 334-337
- Test hardcodes config-dependent value · Line 659-659
- Test hardcodes config-dependent value · Line 697-697
- Test hardcodes config-dependent value · Line 734-734
- Test hardcodes config-dependent value · Line 893-893
Review Details
-
Files reviewed - 4 · Commit Range:
a0fdb2a..563edfd- docs/user_docs_versioned_docs/version-6.0.0/configuration/databases.mdx
- superset/db_engine_specs/databricks.py
- tests/unit_tests/db_engine_specs/test_databricks.py
- tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.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 [email protected].
Documentation & Help
|
@rusackas can you look at the code we have at preset and see if there's something missing in this PR? |
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Code Review Agent Run #6f98afActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
… signal The databricks-sql-connector raises a generic RuntimeError with the message "No valid authentication settings!" when no usable credentials are present (e.g. a cleared/expired OAuth2 token). Add it to oauth2_auth_failure_signals so needs_oauth2 bootstraps the OAuth2 dance for that case as well. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Code Review Agent Run #f3d4d7Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
…nt_info Fold two behaviors from Preset's proprietary DatabricksOAuth2Override into the upstream engine spec so the override can be retired cleanly: - impersonate_user now clears the stored credential (URL password and, for the Python connector, connect_args access_token) when no user token is available, forcing the OAuth2 dance instead of silently connecting with a stale token. - Add update_params_from_encrypted_extra to drop the oauth2_client_info block before params reach the driver. That block is the per-database OAuth2 client config read by Database.get_oauth2_config; it is not a driver connection arg, so leaving it in poisons the connection when OAuth2 is configured per database. Both live on DatabricksDynamicBaseEngineSpec, inherited by the Native and Python connector specs. Update and extend unit tests to cover the force-OAuth paths, the URL-only impersonation branch, and the oauth2_client_info stripping. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Code Review Agent Run #3582f0Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
- Add Databricks to the "Impersonate logged in user" checkbox label - Note in the tooltip that Databricks uses OAuth2 to authenticate as the currently logged on user - Add Databricks to the database-name examples in the design guidelines The Databricks OAuth2 impersonation backend was implemented in apache#41421; this surfaces the capability in the connection UI and docs.
SUMMARY
OAuth 2.0 support for Databricks, across AWS, Azure, and GCP.
Adopts #34619 (original work by @drummerwolli, who stepped away). I re-applied their commits on current master and fixed the failing unit tests. Authorship is preserved via co-author trailers.
The only real fix on top of the original work:
get_oauth2_tokenwas overwriting the config's already-resolvedtoken_request_uriwith the AWS template that still had an unsubstituted account-id placeholder, so the token exchange POSTed to.../accounts/{}/v1/token. It now only falls back to the AWS endpoint when no URI is configured. No behavioral change to the feature otherwise.TESTING INSTRUCTIONS
Unit tests:
pytest tests/unit_tests/db_engine_specs/test_databricks.py tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.pyADDITIONAL INFORMATION