Skip to content

WorkbenchStrategy() fails if workbench is not a defined profile #413

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
blairj09 opened this issue May 29, 2025 · 1 comment · May be fixed by #414
Open

WorkbenchStrategy() fails if workbench is not a defined profile #413

blairj09 opened this issue May 29, 2025 · 1 comment · May be fixed by #414
Assignees
Labels
sdk Used for automation

Comments

@blairj09
Copy link

In trying to create an app that can run seamlessly locally, in Posit Workbench, and in Posit Connect, I have the following setup to configure my WorkspaceClient:

from databricks.sdk import WorkspaceClient
from databricks.sdk.core import databricks_cli
from posit.workbench.external.databricks import WorkbenchStrategy
from posit.connect.external.databricks import ConnectStrategy, databricks_config

w = WorkspaceClient(
    config = databricks_config(
        posit_default_strategy = databricks_cli,
        posit_workbench_strategy = WorkbenchStrategy(),
        posit_connect_strategy = ConnectStrategy(user_session_token = session_token)
    )
)

w.current_user.me().display_name

However, when I try to create the WorkSpace client, I get this error:

ValueError: resolve: /Users/jamesblair/.databrickscfg has no workbench profile configured. Config: profile=workbench
File [~/Documents/Posit/repos/data-and-ai-summit-2025/.venv/lib/python3.11/site-packages/databricks/sdk/config.py:182](vscode-file://vscode-app/Applications/Positron.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html#), in Config.__init__(self, credentials_provider, credentials_strategy, product, product_version, clock, **kwargs)
    181 self._load_from_env()
--> 182 self._known_file_config_loader()
    183 self._fix_host_if_needed()
Show Traceback

My expectation would be that WorkbenchStrategy() doesn't require a workbench profile unless it's the strategy that will be used. In the case of my local environment, I want to use databricks_cli as my strategy.

@github-actions github-actions bot added the sdk Used for automation label May 29, 2025
@tdstein
Copy link
Collaborator

tdstein commented May 29, 2025

Hey @blairj09,

I'm still investigating a long term solution. In the meantime, here is a temporary workaround:

from databricks.sdk import WorkspaceClient
from databricks.sdk.core import databricks_cli

from posit.connect import _utils
from posit.connect.external.databricks import ConnectStrategy, databricks_config
from posit.workbench.external.databricks import WorkbenchStrategy

session_token = ""

w = WorkspaceClient(
    config=databricks_config(
        posit_default_strategy=databricks_cli,
        posit_workbench_strategy=WorkbenchStrategy() if _utils.is_workbench() else None,
        posit_connect_strategy=ConnectStrategy(user_session_token=session_token),
    )
)

print(w.current_user.me().display_name)

This avoids instantiating WorkbenchStrategy unless the any of the standard Workbench environment variables are found: https://github.com/posit-dev/posit-sdk-py/blob/main/src/posit/connect/_utils.py#L35

Alternatively, you can add a ["workbench"] entry to your ~/.databrickscfg file.

[workbench]
host  = https://***.cloud.databricks.com/
token = *****

This gets around the error by making WorkbenchStrategy think there is a "workbench" profile.

@tdstein tdstein self-assigned this May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdk Used for automation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants