Skip to content

fix: prevent _cache_dbr_capabilities from caching None-version entries (#1398)#1414

Merged
sd-db merged 6 commits intomainfrom
sd-db/triage/dbt-issue-1398-cache-poisoning
Apr 27, 2026
Merged

fix: prevent _cache_dbr_capabilities from caching None-version entries (#1398)#1414
sd-db merged 6 commits intomainfrom
sd-db/triage/dbt-issue-1398-cache-poisoning

Conversation

@sd-db
Copy link
Copy Markdown
Collaborator

@sd-db sd-db commented Apr 21, 2026

Fixes #1398.

_cache_dbr_capabilities was caching DBRCapabilities(dbr_version=None) when _query_dbr_version() failed, and the idempotency guard then blocked every retry — silently disabling all version-gated features for the life of the process.

Fix: apply the same None-guard already used by the sibling _try_cache_dbr_capabilities, and switch the downstream read in open() to .get(..., DBRCapabilities()) so a now-possibly-missing entry doesn't KeyError. Failure-case behavior is unchanged for the current connection; subsequent open() calls can now retry instead of staying stuck.

Follow-ups tracked in #1413.

Test plan

#1398)

When _query_dbr_version() returns None after a successful connection (e.g.
transient failure on `SET spark.databricks.clusterUsageTags.sparkVersion`),
_cache_dbr_capabilities would write DBRCapabilities(dbr_version=None) to the
class-level cache, and the idempotency guard at the top of the method would
block every subsequent re-query — silently disabling every version-gated
feature for the life of the process.

Apply the same None-guard already present in _try_cache_dbr_capabilities, and
switch the downstream read in open() to .get() with a default DBRCapabilities()
so the now-possibly-missing entry no longer KeyErrors.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks
  connections.py 194-196, 506
Project Total  

This report was generated by python-coverage-comment-action

@sd-db sd-db self-assigned this Apr 22, 2026
Comment thread dbt/adapters/databricks/connections.py Outdated
Comment thread dbt/adapters/databricks/connections.py Outdated
sd-db added 3 commits April 25, 2026 10:47
After the #1398 fix, _cache_dbr_capabilities and _try_cache_dbr_capabilities
have identical bodies. Keep _cache_dbr_capabilities (absorbing the rationale
for the None-guard into its docstring), update the lone caller in
_create_fresh_connection, and drop the now-redundant TestTryCacheDbr class.

Addresses review feedback on #1414.
The cache it reads (_dbr_capabilities_cache) is a class attribute, and the
sibling writer (_cache_dbr_capabilities) is already a classmethod. Promote
the reader to match, and use it from open() so the same accessor is used
across the class.

Addresses review feedback on #1414.
Comment thread dbt/adapters/databricks/connections.py Outdated
tejassp-db
tejassp-db previously approved these changes Apr 27, 2026
Address review comment on #1414: replace silent `except: pass` in
`_query_dbr_version` with a debug log capturing the http_path and
exception. Debug level is intentional — `_create_fresh_connection`
calls this before `credentials_manager` is set, so the first attempt
per fresh connection always raises and is recovered by the subsequent
`open()` call. Warning would flood the default log on every model run.

Co-authored-by: Isaac
@sd-db
Copy link
Copy Markdown
Collaborator Author

sd-db commented Apr 27, 2026

/integration-test

@github-actions
Copy link
Copy Markdown

Integration tests dispatched for PR #1414 by @sd-db. Track progress in the Actions tab.

@github-actions
Copy link
Copy Markdown

Integration results for PR #1414 — UC cluster ✅ success · SQL warehouse ✅ success · All-purpose cluster ✅ success

Run details.

@sd-db sd-db merged commit c9c9456 into main Apr 27, 2026
7 checks passed
@sd-db sd-db deleted the sd-db/triage/dbt-issue-1398-cache-poisoning branch April 27, 2026 14:31
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.

bug: _cache_dbr_capabilities permanently poisons capability cache when version query fails

2 participants