Pass --force-refresh to CLI auth token command#1378
Conversation
bedfa97 to
f979a2c
Compare
Range-diff: stack/cli-force-refresh (bedfa97 -> f979a2c)
Reproduce locally: |
f979a2c to
b0cd110
Compare
Range-diff: stack/cli-force-refresh (f979a2c -> b0cd110)
Reproduce locally: |
b0cd110 to
bdc451f
Compare
Range-diff: stack/cli-force-refresh (b0cd110 -> bdc451f)
Reproduce locally: |
bdc451f to
8821700
Compare
Range-diff: stack/cli-force-refresh (bdc451f -> 8821700)
Reproduce locally: |
8821700 to
336b9be
Compare
Range-diff: stack/cli-force-refresh (8821700 -> 336b9be)
Reproduce locally: |
336b9be to
96fcf7f
Compare
96fcf7f to
b9159e8
Compare
Range-diff: stack/cli-force-refresh (96fcf7f -> b9159e8)
Reproduce locally: |
b9159e8 to
f8fff86
Compare
563fc02 to
9950b72
Compare
b82a295 to
7cb4c2a
Compare
Range-diff: stack/cli-force-refresh (b82a295 -> 7cb4c2a)
Reproduce locally: |
7cb4c2a to
a78d53c
Compare
9950b72 to
13e5ee8
Compare
13e5ee8 to
343baae
Compare
a78d53c to
1d21609
Compare
1d21609 to
4ca3f62
Compare
simonfaltum
left a comment
There was a problem hiding this comment.
Deep review (2-round swarm: Isaac + Cursor)
Verdict: Approved — no Critical or Major findings. Nits and test-gap suggestions below.
Summary: 0 Critical | 0 Major | 2 Gap (Nit) | 3 Nit | 1 Suggestion
Cross-cutting verification (both reviewers independently confirmed): warning is bounded to one emission per token-source lifetime (_build_cli_command runs once in __init__, refresh() uses cached self._cmd); CliVersion sentinel ordering is correct via @dataclass(order=True) so both CliVersion() and _DEFAULT_DEV_BUILD correctly fail the >= gate; AzureCliTokenSource genuinely unaffected (separate subclass, does not route through DatabricksCliTokenSource._build_cli_command); --force-refresh is a static string so no injection risk; _parse_cli_version intentionally ignores Prerelease (documented design); NEXT_CHANGELOG.md entry is correctly placed under Internal Changes.
Inline comments follow. Most are optional polish; the two test gaps would be nice to close before merge.
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. The SDK manages its own token caching. When the SDK considers its token stale and shells out to `databricks auth token`, the CLI may return a cached token that is about to expire from the SDK's perspective. The --force-refresh flag guarantees a freshly minted token. With the version detection infrastructure from the parent commit, adding --force-refresh is a one-constant, one-if change. See: databricks/cli#4767
|
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. |
🥞 Stacked PR
Use this link to review incremental changes.
Summary
Append
--force-refreshto thedatabricks auth tokencommand when the installed CLI is >= v0.296.0, so the CLI bypasses its internal token cache and hands the SDK a freshly minted token every time.Mirrors databricks/databricks-sdk-go#1628. Requires the version-detection infrastructure from the parent PR #1377.
Why
The SDK already manages its own token caching via
oauth.Refreshable. When the SDK decides it needs a new token and shells out todatabricks auth token, the CLI may return a token from its own cache that is about to expire (or that has already expired from the SDK's perspective). That produces unnecessary refresh failures and retry loops on top of a value that the SDK was confident was fresh.The CLI added
--force-refreshin databricks/cli#4767 (motivated by databricks/cli#4564) specifically to let callers bypass the CLI's cache. With the version-detection infrastructure from the parent PR already in place, opting in is a one-constant, one-branch change.What changed
Interface changes
None.
CliTokenSourceis not part of the public API surface.Behavioral changes
databricks auth tokeninvocations now end with--force-refreshwhenever the detected CLI is >= v0.296.0. Callers on older CLIs see no change.WARNINGis logged:"Databricks CLI <ver> does not support --force-refresh (requires >= v0.296.0). The CLI's token cache may provide stale tokens."AzureCliTokenSourceis unaffected — it does not pass throughDatabricksCliTokenSourceand does not opt into version-gated flag selection.Internal changes
DatabricksCliTokenSource._CLI_VERSION_FOR_FORCE_REFRESH = CliVersion(0, 296, 0)._build_cli_commandis split into two helpers, matching the shape the Go SDK settled on after the same PR there:_build_core_cli_command(cli_path, cfg, version)— holds the existing profile-vs-host decision (moved out of_build_cli_command)._build_cli_command(cli_path, cfg, version)— now a thin wrapper that calls_build_core_cli_command, appends--force-refreshwhenversion >= _CLI_VERSION_FOR_FORCE_REFRESH, and otherwise logs the unsupported-versionWARNING.Future version-gated flags slot into the same pattern: add a
_CLI_VERSION_FOR_<flag>constant and anif version >= ...block in_build_cli_command.How is this tested?
Unit tests in
tests/test_credentials_provider.py:test_build_cli_commandcases covering the full matrix:--host+ v0.296.0 → appends--force-refresh.--host+ v0.296.0 → appends--force-refresh.--profile+ v0.296.0 →--profile+--force-refresh.--profile+ v0.207.1 →--profileonly (too old for--force-refresh).--profile-only + v0.296.0 →--profile+--force-refresheven without a host.--hostonly, no--force-refresh.test_build_cli_command_force_refresh_unsupported_logs_warning— asserts theWARNINGlog is emitted whenversion < _CLI_VERSION_FOR_FORCE_REFRESH.All parent-PR tests continue to pass unchanged.