Skip to content

Commit 53e99a5

Browse files
Fix null body response to empty in ApiClient (#579)
## 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 <[email protected]>
1 parent e10bd59 commit 53e99a5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

databricks/sdk/core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,14 @@ def do(self,
145145
if not len(response.content):
146146
return resp
147147

148-
json = response.json()
149-
if isinstance(json, list):
150-
return json
148+
jsonResponse = response.json()
149+
if jsonResponse is None:
150+
return resp
151+
152+
if isinstance(jsonResponse, list):
153+
return jsonResponse
151154

152-
return {**resp, **json}
155+
return {**resp, **jsonResponse}
153156

154157
@staticmethod
155158
def _is_retryable(err: BaseException) -> Optional[str]:

tests/test_core.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,21 @@ def test_shares(config, requests_mock):
335335
assert requests_mock.last_request.json() == {'changes': [{'principal': 'principal'}]}
336336

337337

338+
def test_deletes(config, requests_mock):
339+
requests_mock.delete("http://localhost/api/2.0/preview/sql/alerts/alertid",
340+
request_headers={"User-Agent": config.user_agent},
341+
text="null",
342+
)
343+
344+
w = WorkspaceClient(config=config)
345+
res = w.alerts.delete(alert_id="alertId")
346+
347+
assert requests_mock.call_count == 1
348+
assert requests_mock.called
349+
350+
assert res is None
351+
352+
338353
def test_error(config, requests_mock):
339354
errorJson = {
340355
"message":

0 commit comments

Comments
 (0)