Skip to content

Commit 9af2630

Browse files
Create a deepcopy of config when creating workspace client from account client (#542)
## Changes * We are creating a shallow copy of the config object when creating a ws client from acc client. This leads to the config of acc client being overridden by changes made for the workspace client. This PR makes it so that we are making a deepcopy instead. * Also, correctly handle list response jsons in the API client. ## Tests * added integration test - [ ] `make test` run locally - [ ] `make fmt` applied - [ ] relevant integration tests applied
1 parent 85ba774 commit 9af2630

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

databricks/sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

databricks/sdk/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,8 @@ def copy(self):
457457
cpy: Config = copy.copy(self)
458458
cpy._user_agent_other_info = copy.deepcopy(self._user_agent_other_info)
459459
return cpy
460+
461+
def deep_copy(self):
462+
"""Creates a deep copy of the config object.
463+
"""
464+
return copy.deepcopy(self)

databricks/sdk/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ def do(self,
142142
resp[header] = response.headers.get(Casing.to_header_case(header))
143143
if not len(response.content):
144144
return resp
145-
return {**resp, **response.json()}
145+
146+
json = response.json()
147+
if isinstance(json, list):
148+
return json
149+
150+
return {**resp, **json}
146151

147152
@staticmethod
148153
def _is_retryable(err: BaseException) -> Optional[str]:

tests/integration/test_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,13 @@ def test_get_workspace_client(a):
1414
def test_get_workspace_id(ucws, env_or_skip):
1515
ws_id = int(env_or_skip('THIS_WORKSPACE_ID'))
1616
assert ucws.get_workspace_id() == ws_id
17+
18+
19+
def test_creating_ws_client_from_ac_client_does_not_override_config(a):
20+
wss = list(a.workspaces.list())
21+
if len(wss) == 0:
22+
pytest.skip("no workspaces")
23+
a.get_workspace_client(wss[0])
24+
25+
# assert doesn't throw
26+
wss = list(a.workspaces.list())

0 commit comments

Comments
 (0)