Skip to content
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

Fix null body response to empty in ApiClient #579

Merged
merged 12 commits into from
May 16, 2024
11 changes: 7 additions & 4 deletions databricks/sdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,14 @@ def do(self,
if not len(response.content):
return resp

json = response.json()
if isinstance(json, list):
return json
jsonResponse = response.json()
if jsonResponse is None:
return resp

if isinstance(jsonResponse, list):
return jsonResponse

return {**resp, **json}
return {**resp, **jsonResponse}

@staticmethod
def _is_retryable(err: BaseException) -> Optional[str]:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@ def test_shares(config, requests_mock):
assert requests_mock.last_request.json() == {'changes': [{'principal': 'principal'}]}


def test_deletes(config, requests_mock):
requests_mock.delete("http://localhost/api/2.0/preview/sql/alerts/alertid",
request_headers={"User-Agent": config.user_agent},
text="null",
)

w = WorkspaceClient(config=config)
res = w.alerts.delete(alert_id="alertId")

assert requests_mock.call_count == 1
assert requests_mock.called

assert res is None


def test_error(config, requests_mock):
errorJson = {
"message":
Expand Down
Loading