-
Notifications
You must be signed in to change notification settings - Fork 193
Call _resolve_host_metadata on Config init and make failures non-fatal #1318
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
Merged
hectorcast-db
merged 2 commits into
main
from
hectorcast-db/stack/resolve-host-metadata-on-init
Mar 11, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -820,69 +820,75 @@ def test_databricks_oidc_endpoints_uses_discovery_url(requests_mock): | |
| "account_id": _DUMMY_ACCOUNT_ID, | ||
| "workspace_id": _DUMMY_WORKSPACE_ID, | ||
| }, | ||
| {}, | ||
| {"experimental_is_unified_host": True}, | ||
| { | ||
| "account_id": _DUMMY_ACCOUNT_ID, | ||
| "workspace_id": _DUMMY_WORKSPACE_ID, | ||
| "discovery_url": f"{_DUMMY_WS_HOST}/oidc", | ||
| }, | ||
| id="workspace-populates-all-fields", | ||
| id="unified-populates-all-fields", | ||
| ), | ||
| pytest.param( | ||
| _DUMMY_ACC_HOST, | ||
| {"oidc_endpoint": f"{_DUMMY_ACC_HOST}/oidc/accounts/{{account_id}}"}, | ||
| {"account_id": _DUMMY_ACCOUNT_ID}, | ||
| {"account_id": _DUMMY_ACCOUNT_ID, "experimental_is_unified_host": True}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| {"discovery_url": f"{_DUMMY_ACC_HOST}/oidc/accounts/{_DUMMY_ACCOUNT_ID}"}, | ||
| id="account-substitutes-account-id", | ||
| id="unified-substitutes-account-id", | ||
| ), | ||
| pytest.param( | ||
| _DUMMY_WS_HOST, | ||
| {"oidc_endpoint": f"{_DUMMY_WS_HOST}/oidc", "account_id": "other-account", "workspace_id": "other-ws"}, | ||
| { | ||
| "account_id": _DUMMY_ACCOUNT_ID, | ||
| "workspace_id": _DUMMY_WORKSPACE_ID, | ||
| "experimental_is_unified_host": True, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| }, | ||
| {"account_id": _DUMMY_ACCOUNT_ID, "workspace_id": _DUMMY_WORKSPACE_ID}, | ||
| {"account_id": _DUMMY_ACCOUNT_ID, "workspace_id": _DUMMY_WORKSPACE_ID}, | ||
| id="does-not-overwrite-existing-fields", | ||
| id="unified-does-not-overwrite-existing-fields", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_resolve_host_metadata(requests_mock, host, response_json, config_kwargs, expected_fields): | ||
| requests_mock.get(f"{host}/.well-known/databricks-config", json=response_json) | ||
| def test_resolve_host_metadata(mocker, host, response_json, config_kwargs, expected_fields): | ||
| mocker.patch("databricks.sdk.config.get_host_metadata", return_value=oauth.HostMetadata.from_dict(response_json)) | ||
| config = Config(host=host, token="t", **config_kwargs) | ||
| config._resolve_host_metadata() | ||
| for field, expected in expected_fields.items(): | ||
| assert getattr(config, field) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "host,response_json,status_code,config_kwargs,error_match", | ||
| [ | ||
| pytest.param( | ||
| _DUMMY_ACC_HOST, | ||
| {"oidc_endpoint": f"{_DUMMY_ACC_HOST}/oidc/accounts/{{account_id}}"}, | ||
| 200, | ||
| {}, | ||
| "account_id is not configured", | ||
| id="missing-account-id", | ||
| ), | ||
| pytest.param( | ||
| _DUMMY_WS_HOST, | ||
| {"account_id": _DUMMY_ACCOUNT_ID}, | ||
| 200, | ||
| {}, | ||
| "discovery_url is not configured", | ||
| id="missing-oidc-endpoint", | ||
| ), | ||
| pytest.param( | ||
| _DUMMY_WS_HOST, | ||
| {}, | ||
| 500, | ||
| {}, | ||
| "Failed to fetch host metadata", | ||
| id="http-error", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_resolve_host_metadata_raises(requests_mock, host, response_json, status_code, config_kwargs, error_match): | ||
| requests_mock.get(f"{host}/.well-known/databricks-config", status_code=status_code, json=response_json) | ||
| config = Config(host=host, token="t", **config_kwargs) | ||
| with pytest.raises(ValueError, match=error_match): | ||
| config._resolve_host_metadata() | ||
| def test_resolve_host_metadata_missing_account_id(mocker): | ||
| """Raises when the oidc_endpoint template requires account_id but none is configured.""" | ||
| mocker.patch( | ||
| "databricks.sdk.config.get_host_metadata", | ||
| return_value=oauth.HostMetadata.from_dict({"oidc_endpoint": f"{_DUMMY_ACC_HOST}/oidc/accounts/{{account_id}}"}), | ||
| ) | ||
| with pytest.raises(ValueError, match="account_id is required to resolve discovery_url"): | ||
| Config(host=_DUMMY_ACC_HOST, token="t", experimental_is_unified_host=True) | ||
|
|
||
|
|
||
| def test_resolve_host_metadata_no_oidc_endpoint(mocker): | ||
| """No raise when metadata has no oidc_endpoint; discovery_url stays unset.""" | ||
| mocker.patch( | ||
| "databricks.sdk.config.get_host_metadata", | ||
| return_value=oauth.HostMetadata.from_dict({"account_id": _DUMMY_ACCOUNT_ID}), | ||
| ) | ||
| config = Config(host=_DUMMY_WS_HOST, token="t", experimental_is_unified_host=True) | ||
| assert config.account_id == _DUMMY_ACCOUNT_ID | ||
| assert config.discovery_url is None | ||
|
|
||
|
|
||
| def test_resolve_host_metadata_http_error(mocker): | ||
| """HTTP failure is swallowed with a warning; fields remain unset.""" | ||
| mocker.patch( | ||
| "databricks.sdk.config.get_host_metadata", | ||
| side_effect=ValueError(f"Failed to fetch host metadata from {_DUMMY_WS_HOST}/.well-known/databricks-config"), | ||
| ) | ||
| config = Config(host=_DUMMY_WS_HOST, token="t", experimental_is_unified_host=True) | ||
| assert config.account_id is None | ||
| assert config.discovery_url is None | ||
|
|
||
|
|
||
| def test_resolve_host_metadata_skipped_for_non_unified(mocker): | ||
| """Metadata resolution is skipped entirely for non-unified (workspace/account) hosts.""" | ||
| mock_get = mocker.patch("databricks.sdk.config.get_host_metadata") | ||
| Config(host=_DUMMY_WS_HOST, token="t") | ||
| mock_get.assert_not_called() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're replacing a test for the general case with a test for the experimental flag case. Shouldn't we have both until the flag is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this test was always for the unified path.
The always called the resolve_metadata_path, but now this is skipped if the flag is false.