Skip to content

Commit 8be1f12

Browse files
Fix cache re-creation
1 parent 8ee7c50 commit 8be1f12

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

databricks/sdk/config.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from . import useragent
1414
from ._base_client import _fix_host_if_needed
1515
from .clock import Clock, RealClock
16-
from .credentials_provider import CredentialsStrategy, DefaultCredentials
16+
from .credentials_provider import CredentialsStrategy, DefaultCredentials, OAuthCredentialsProvider
1717
from .environments import (ALL_ENVS, AzureEnvironment, Cloud,
1818
DatabricksEnvironment, get_environment_for_hostname)
1919
from .oauth import (OidcEndpoints, Token, get_account_endpoints,
@@ -200,7 +200,19 @@ def __init__(
200200
raise ValueError(message) from e
201201

202202
def oauth_token(self) -> Token:
203-
return self._credentials_strategy.oauth_token(self)
203+
"""Returns the OAuth token from the current credential provider.
204+
205+
This method only works when using OAuth-based authentication methods.
206+
If the current credential provider is an OAuthCredentialsProvider, it reuses
207+
the existing provider. Otherwise, it raises a ValueError indicating that
208+
OAuth tokens are not available for the current authentication method.
209+
"""
210+
# Check if the current header factory is an OAuthCredentialsProvider
211+
if isinstance(self._header_factory, OAuthCredentialsProvider):
212+
return self._header_factory.oauth_token()
213+
# Raise an error for non-OAuth authentication methods
214+
raise ValueError(f"OAuth tokens are not available for {self.auth_type} authentication. "
215+
f"Use an OAuth-based authentication method to access OAuth tokens.")
204216

205217
def wrap_debug_info(self, message: str) -> str:
206218
debug_string = self.debug_string()

0 commit comments

Comments
 (0)