Skip to content

Commit fbf7ccd

Browse files
Merge branch 'main' into implement-incremental-uploads
2 parents 6679798 + 3a183ce commit fbf7ccd

File tree

8 files changed

+779
-172
lines changed

8 files changed

+779
-172
lines changed

NEXT_CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
### Documentation
1010

1111
### Internal Changes
12+
13+
* Refactor `DatabricksError` to expose different types of error details ([#912](https://github.com/databricks/databricks-sdk-py/pull/912)).
1214
* Update Jobs ListJobs API to support paginated responses ([#896](https://github.com/databricks/databricks-sdk-py/pull/896))
1315
* Update Jobs ListRuns API to support paginated responses ([#890](https://github.com/databricks/databricks-sdk-py/pull/890))
1416
* Introduce automated tagging ([#888](https://github.com/databricks/databricks-sdk-py/pull/888))
1517
* Update Jobs GetJob API to support paginated responses ([#869](https://github.com/databricks/databricks-sdk-py/pull/869)).
18+
* Update On Behalf Of User Authentication in Multithreaded applications ([#907](https://github.com/databricks/databricks-sdk-py/pull/907))
1619

1720
### API Changes

databricks/sdk/credentials_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,8 @@ def _get_model_dependency_oauth_token(self, should_retry=True) -> str:
853853
return self.current_token
854854

855855
def _get_invokers_token(self):
856-
current_thread = threading.current_thread()
857-
thread_data = current_thread.__dict__
856+
main_thread = threading.main_thread()
857+
thread_data = main_thread.__dict__
858858
invokers_token = None
859859
if "invokers_token" in thread_data:
860860
invokers_token = thread_data["invokers_token"]

databricks/sdk/errors/base.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
import requests
77

8+
from . import details as errdetails
89

10+
11+
# Deprecated.
912
class ErrorDetail:
1013
def __init__(
1114
self,
@@ -22,17 +25,18 @@ def __init__(
2225

2326
@classmethod
2427
def from_dict(cls, d: Dict[str, any]) -> "ErrorDetail":
25-
if "@type" in d:
26-
d["type"] = d["@type"]
27-
return cls(**d)
28+
# Key "@type" is not a valid keyword argument name in Python. Rename
29+
# it to "type" to avoid conflicts.
30+
safe_args = {}
31+
for k, v in d.items():
32+
safe_args[k if k != "@type" else "type"] = v
33+
34+
return cls(**safe_args)
2835

2936

3037
class DatabricksError(IOError):
3138
"""Generic error from Databricks REST API"""
3239

33-
# Known ErrorDetail types
34-
_error_info_type = "type.googleapis.com/google.rpc.ErrorInfo"
35-
3640
def __init__(
3741
self,
3842
message: str = None,
@@ -54,11 +58,11 @@ def __init__(
5458
:param status: [Deprecated]
5559
:param scimType: [Deprecated]
5660
:param error: [Deprecated]
57-
:param retry_after_secs:
61+
:param retry_after_secs: [Deprecated]
5862
:param details:
5963
:param kwargs:
6064
"""
61-
# SCIM-specific parameters are deprecated
65+
# SCIM-specific parameters are deprecated.
6266
if detail:
6367
warnings.warn(
6468
"The 'detail' parameter of DatabricksError is deprecated and will be removed in a future version."
@@ -72,12 +76,18 @@ def __init__(
7276
"The 'status' parameter of DatabricksError is deprecated and will be removed in a future version."
7377
)
7478

75-
# API 1.2-specific parameters are deprecated
79+
# API 1.2-specific parameters are deprecated.
7680
if error:
7781
warnings.warn(
7882
"The 'error' parameter of DatabricksError is deprecated and will be removed in a future version."
7983
)
8084

85+
# Retry-after is deprecated.
86+
if retry_after_secs:
87+
warnings.warn(
88+
"The 'retry_after_secs' parameter of DatabricksError is deprecated and will be removed in a future version."
89+
)
90+
8191
if detail:
8292
# Handle SCIM error message details
8393
# @see https://tools.ietf.org/html/rfc7644#section-3.7.3
@@ -88,20 +98,32 @@ def __init__(
8898
# add more context from SCIM responses
8999
message = f"{scimType} {message}".strip(" ")
90100
error_code = f"SCIM_{status}"
101+
91102
super().__init__(message if message else error)
92103
self.error_code = error_code
93104
self.retry_after_secs = retry_after_secs
94-
self.details = [ErrorDetail.from_dict(detail) for detail in details] if details else []
105+
self._error_details = errdetails.parse_error_details(details)
95106
self.kwargs = kwargs
96107

108+
# Deprecated.
109+
self.details = []
110+
if details:
111+
for d in details:
112+
if not isinstance(d, dict):
113+
continue
114+
self.details.append(ErrorDetail.from_dict(d))
115+
97116
def get_error_info(self) -> List[ErrorDetail]:
98-
return self._get_details_by_type(DatabricksError._error_info_type)
117+
return self._get_details_by_type(errdetails._ERROR_INFO_TYPE)
99118

100119
def _get_details_by_type(self, error_type) -> List[ErrorDetail]:
101-
if self.details == None:
120+
if self.details is None:
102121
return []
103122
return [detail for detail in self.details if detail.type == error_type]
104123

124+
def get_error_details(self) -> errdetails.ErrorDetails:
125+
return self._error_details
126+
105127

106128
@dataclass
107129
class _ErrorOverride:

0 commit comments

Comments
 (0)