Skip to content

Pass --force-refresh to CLI auth token command#1628

Open
mihaimitrea-db wants to merge 2 commits intomainfrom
mihaimitrea-db/stack/cli-force-refresh-v2
Open

Pass --force-refresh to CLI auth token command#1628
mihaimitrea-db wants to merge 2 commits intomainfrom
mihaimitrea-db/stack/cli-force-refresh-v2

Conversation

@mihaimitrea-db
Copy link
Copy Markdown
Contributor

Summary

Pass --force-refresh to the Databricks CLI auth token command 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 to databricks 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-refresh flag (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-refresh is a one-constant, one-if change.

What changed

Interface changes

None. CliTokenSource is not part of the public API surface.

Behavioral changes

  • The SDK now appends --force-refresh when invoking databricks auth token if the CLI version is >= v0.296.0.
  • A warning is logged when the CLI is too old for --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-refresh after the base command is resolved.

How is this tested?

Additional test cases in TestBuildCliCommand:

  • host + v0.296.0 → appends --force-refresh
  • host + v0.200.0 → no --force-refresh
  • account host + v0.296.0 → appends --force-refresh
  • profile + v0.296.0 → --profile + --force-refresh
  • profile + v0.207.1 → --profile only (no --force-refresh)
  • profile-only + v0.296.0 → --profile + --force-refresh
  • zero version → --host only, no --force-refresh

@mihaimitrea-db mihaimitrea-db changed the base branch from mihaimitrea-db/stack/generalize-cli-commands to main April 14, 2026 13:44
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/cli-force-refresh-v2 branch from acce330 to 9bf2816 Compare April 14, 2026 14:08
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/cli-force-refresh-v2 branch from 9bf2816 to 96e0e97 Compare April 14, 2026 14:15
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/cli-force-refresh-v2 branch from 96e0e97 to 69674ff Compare April 14, 2026 14:22
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/cli-force-refresh-v2 branch from 69674ff to 7972862 Compare April 14, 2026 14:30
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>
@mihaimitrea-db mihaimitrea-db force-pushed the mihaimitrea-db/stack/cli-force-refresh-v2 branch from 7972862 to 4b7bfb7 Compare April 14, 2026 14:33
@github-actions
Copy link
Copy Markdown

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-go

Inputs:

  • PR number: 1628
  • Commit SHA: 4b7bfb74fa01282580461ef901eb5ee62230384f

Checks will be approved automatically on success.

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.

1 participant