Skip to content

Commit

Permalink
Fix null body response to empty in ApiClient (#579)
Browse files Browse the repository at this point in the history
## Changes
<!-- Summary of your changes that are easy to understand -->
Some delete end points return null instead of empty body, we fix that in
SDK Client since the APIs are not available publicly and support isn't
available for them yet.

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->
Thanks to @sodle-splunk for contributing the unit test
(#641)
- [x] `make test` run locally
- [x] `make fmt` applied
- [ ] relevant integration tests applied

---------

Co-authored-by: Scott Odle <sodle@splunk.com>
  • Loading branch information
tanmay-db and sodle-splunk committed May 16, 2024
1 parent e10bd59 commit 53e99a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
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

0 comments on commit 53e99a5

Please sign in to comment.