You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix CLI token source --profile fallback with version detection (#1377)
## 🥞 Stacked PR
Use this
[link](https://github.com/databricks/databricks-sdk-py/pull/1377/files)
to review incremental changes.
-
[**stack/cli-force-refresh**](#1377)
[[Files
changed](https://github.com/databricks/databricks-sdk-py/pull/1377/files)]
-
[stack/cli-progressive-token-commands](#1378)
[[Files
changed](https://github.com/databricks/databricks-sdk-py/pull/1378/files/c714a135fb7e9a105b78baa73f203a3875903c78..cfbf51b7c0f71e81183e62b69a81733dbdeea2ea)]
---------
## Summary
Replace the broken error-based `--profile` fallback in `CliTokenSource`
with version-based CLI detection at init time. Mirrors
[databricks/databricks-sdk-go#1605](databricks/databricks-sdk-go#1605).
## Why
`--profile` on `databricks auth token` is a global Cobra flag, so old
CLIs (< v0.207.1) **silently accept it** and then fail with `"cannot
fetch credentials"` instead of `"unknown flag: --profile"`. The existing
retry check was matching on the latter and never fired — the `--host`
fallback it gated was effectively dead code. Switching to `databricks
version` + a minimum-version constant makes the fallback reliable and
sets up future capability-gated flags (e.g. `--force-refresh` in
[#1378](#1378))
without additional subprocess calls.
## What changed
### Interface changes
None. `CliTokenSource` and `DatabricksCliTokenSource` are not part of
the public API surface.
### Behavioral changes
- `cfg.profile` + CLI < v0.207.1 now correctly falls back to `--host`
(previously broken).
- `databricks version` failures log a `WARNING` and fall back to the
most conservative command.
- A default dev build (`v0.0.0-dev[+commit]`) logs an `INFO` explaining
why feature gates are conservative.
- Error messages for missing configuration are precise (`"neither
profile nor host is configured"` / `"…does not support --profile … and
no host fallback is configured"`) instead of a single generic message.
`AzureCliTokenSource` is untouched.
### Internal changes
- New `CliVersion` dataclass with semver-aware comparison operators and
an `is_default_dev_build` property.
- `CliTokenSource` simplified to a single `cmd`; the `fallback_cmd`
parameter and its retry logic are removed.
- `DatabricksCliTokenSource` gains `_get_cli_version`,
`_resolve_cli_command`, `_build_cli_command`, and `_build_host_command`
helpers.
## How is this tested?
Unit tests in `tests/test_credentials_provider.py` cover version
parsing, comparison operators, dev-build detection, command assembly for
every profile/host/version combination, precise error messages, and
logging behavior on detection failure and dev builds. Existing
`tests/test_core.py::test_databricks_cli_token_source_*` tests pass
unchanged.
Copy file name to clipboardExpand all lines: NEXT_CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,15 @@
7
7
### Security
8
8
9
9
### Bug Fixes
10
+
* Fixed Databricks CLI `--profile` fallback by detecting the CLI version at init time. The previous error-based detection was broken because `--profile` is a global Cobra flag silently accepted by old CLIs.
10
11
11
12
### Documentation
12
13
13
14
### Breaking Changes
14
15
15
16
### Internal Changes
17
+
* Detect Databricks CLI version at init time via `databricks version`, enabling version-gated flag support without additional subprocess calls.
18
+
* Validate Databricks CLI configuration at `DatabricksCliTokenSource.__init__` time. Misconfiguration (missing profile and host, or `--profile`-unsupported CLI without a host fallback) now surfaces as `IOError` synchronously from construction rather than lazily from the first `refresh()` call. The exception type matches the previous `refresh()`-time behaviour, so callers who already catch `IOError` are unaffected.
0 commit comments