Skip to content

fix(databricks): lazy-load the “workbench” profile #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tdstein
Copy link
Collaborator

@tdstein tdstein commented May 29, 2025

Defer loading of the default “workbench” credentials until they’re actually needed in WorkbenchStrategy.__call__. Previously we loaded the profile eagerly, which could raise if you never used it in a given context.

Resolves #413

Defer loading of the default “workbench” credentials until they’re actually
needed in `WorkbenchStrategy.__call__`. Previously we loaded the profile
eagerly, which could raise if you never used it in a given context.
Copy link

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1903 1794 94% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/posit/workbench/external/databricks.py 86% 🟢
TOTAL 86% 🟢

updated for commit: 7f099e7 by action🐍

@tdstein tdstein requested review from Copilot, dbkegley, plascaray and a team May 29, 2025 14:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR defers loading of the default “workbench” profile until the strategy is invoked and updates tests accordingly.

  • Lazy-load Config(profile="workbench") in WorkbenchStrategy._config instead of on init
  • Simplify the credentials provider to a lambda in __call__
  • Adjust and add tests for default and provided-Config behaviors

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/posit/workbench/external/test_databricks.py Rename and expand tests to cover lazy-loading and provided Config
src/posit/workbench/external/databricks.py Delay instantiation of default Config and return a lambda for credentials
Comments suppressed due to low confidence (3)

tests/posit/workbench/external/test_databricks.py:21

  • The test is matching on 'profile=workbench', but the raised error is "Missing value for field 'token' in Config.". Update the regex to match the actual message, e.g., match="Missing value for field 'token'".
with pytest.raises(ValueError, match="profile=workbench"):

tests/posit/workbench/external/test_databricks.py:24

  • [nitpick] Test name is ambiguous. Rename it to reflect that it verifies behavior when a Config is provided, e.g., test_with_provided_config_strategy.
def test_workbench_strategy(self):

tests/posit/workbench/external/test_databricks.py:26

  • Add an assertion to verify that calling the strategy returns the expected Authorization header, e.g., headers = cs(); assert headers() == {'Authorization': 'Bearer token'}.
cs = WorkbenchStrategy(
    config=Config(host="https://databricks.com/workspace", token="token")

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.

WorkbenchStrategy() fails if workbench is not a defined profile
1 participant