Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions databricks/sdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import requests

from . import useragent
from ._base_client import _fix_host_if_needed
from ._base_client import _BaseClient, _fix_host_if_needed
from .client_types import ClientType, HostType
from .clock import Clock, RealClock
from .credentials_provider import CredentialsStrategy, DefaultCredentials, OAuthCredentialsProvider
Expand Down Expand Up @@ -637,8 +637,17 @@ def _resolve_host_metadata(self) -> None:
"""
if not self.host:
return
# Host metadata is a best-effort discovery probe that falls back to the
# explicit configuration below on any failure. Build its client from the
# configured timeouts: otherwise it uses the default 300s retry budget,
# which blocks Config() initialization for ~5 minutes when the host is
# unreachable.
client = _BaseClient(
retry_timeout_seconds=self.retry_timeout_seconds,
http_timeout_seconds=self.http_timeout_seconds,
)
try:
meta = get_host_metadata(self.host)
meta = get_host_metadata(self.host, client=client)
except Exception as e:
logger.warning(
f"Failed to automatically resolve config from host metadata: {e}. Falling back to explicit user provided configuration."
Expand Down
13 changes: 13 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,19 @@ def test_resolve_host_metadata_called_for_non_unified(mocker):
mock_get.assert_called_once()


def test_resolve_host_metadata_uses_configured_timeouts(mocker):
"""The discovery client honors the configured timeouts so an unreachable host
cannot block Config() init for the default 300s retry budget."""
mock_get = mocker.patch(
"databricks.sdk.config.get_host_metadata",
return_value=oauth.HostMetadata(oidc_endpoint=""),
)
Config(host=_DUMMY_WS_HOST, token="t", retry_timeout_seconds=7, http_timeout_seconds=3)
client = mock_get.call_args.kwargs["client"]
assert client._retry_timeout_seconds == 7
assert client._http_timeout_seconds == 3


# ---------------------------------------------------------------------------
# Cloud field tests
# ---------------------------------------------------------------------------
Expand Down
Loading