Pass --force-refresh to CLI auth token command#1628
Open
mihaimitrea-db wants to merge 2 commits intomainfrom
Open
Pass --force-refresh to CLI auth token command#1628mihaimitrea-db wants to merge 2 commits intomainfrom
mihaimitrea-db wants to merge 2 commits intomainfrom
Conversation
acce330 to
9bf2816
Compare
9bf2816 to
96e0e97
Compare
96e0e97 to
69674ff
Compare
69674ff to
7972862
Compare
The --profile flag is a global Cobra flag in the Databricks CLI. Old CLIs (< v0.207.1) silently accept it on `auth token` but fail with "cannot fetch credentials" instead of "unknown flag: --profile". This made the previous error-based fallback to --host dead code. Replace the try-and-retry approach with version-based detection: run `databricks version` at init time and use the parsed semver to decide between --profile and --host. This also simplifies CliTokenSource to a single resolved command with no runtime probing. Signed-off-by: Mihai Mitrea <mihai.mitrea@databricks.com>
Append --force-refresh when the CLI version supports it (>= v0.296.0), bypassing the CLI's internal token cache. The SDK manages its own caching via CachedTokenSource, so a fresh token on every CLI call eliminates stale-token issues. Signed-off-by: Mihai Mitrea <mihai.mitrea@databricks.com>
7972862 to
4b7bfb7
Compare
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
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
Pass
--force-refreshto the Databricks CLIauth tokencommand when the CLI supports it (>= v0.296.0), bypassing the CLI's internal token cache.Why
The SDK manages its own token caching via
CachedTokenSource. When the SDK decides it needs a new token and shells out todatabricks auth token, the CLI may return a cached token that is about to expire (or has already expired from the SDK's perspective). This creates unnecessary refresh failures and retry loops.The CLI added a
--force-refreshflag (databricks/cli#4767, motivated by databricks/cli#4564) that bypasses its internal cache. By using this flag, the SDK is guaranteed a freshly minted token every time it asks for one.With the version detection infrastructure from the parent PR (#1605), adding
--force-refreshis a one-constant, one-ifchange.What changed
Interface changes
None.
CliTokenSourceis not part of the public API surface.Behavioral changes
--force-refreshwhen invokingdatabricks auth tokenif the CLI version is >= v0.296.0.--force-refresh:"Databricks CLI v%s does not support --force-refresh (requires >= v%s). The CLI's token cache may provide stale tokens."Internal changes
cliVersionForForceRefresh: new version constant{0, 296, 0}.buildCliCommand: adds a nil guard and appends--force-refreshafter the base command is resolved.How is this tested?
Additional test cases in
TestBuildCliCommand:--force-refresh--force-refresh--force-refresh--profile+--force-refresh--profileonly (no--force-refresh)--profile+--force-refresh--hostonly, no--force-refresh