Skip to content

Commit 13a0a2f

Browse files
Parsing functions for nested dataclasses
1 parent 86a5e38 commit 13a0a2f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

databricks/sdk/errors/details.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ def _parse_debug_info(d: Dict[str, Any]) -> DebugInfo:
296296
return di
297297

298298

299+
def _parse_quota_failure_violation(d: Dict[str, Any]) -> QuotaFailureViolation:
300+
return QuotaFailureViolation(
301+
subject=_parse_string(d.get("subject", "")),
302+
description=_parse_string(d.get("description", "")),
303+
)
304+
305+
299306
def _parse_quota_failure(d: Dict[str, Any]) -> QuotaFailure:
300307
violations = []
301308
if "violations" in d:
@@ -304,7 +311,7 @@ def _parse_quota_failure(d: Dict[str, Any]) -> QuotaFailure:
304311
for violation in d["violations"]:
305312
if not isinstance(violation, dict):
306313
raise ValueError(f"Expected dict, got {violation!r}")
307-
violations.append(QuotaFailureViolation(**violation))
314+
violations.append(_parse_quota_failure_violation(violation))
308315
return QuotaFailure(violations=violations)
309316

310317

@@ -328,6 +335,13 @@ def _parse_precondition_failure(d: Dict[str, Any]) -> PreconditionFailure:
328335
return PreconditionFailure(violations=violations)
329336

330337

338+
def _parse_bad_request_field_violation(d: Dict[str, Any]) -> BadRequestFieldViolation:
339+
return BadRequestFieldViolation(
340+
field=_parse_string(d.get("field", "")),
341+
description=_parse_string(d.get("description", "")),
342+
)
343+
344+
331345
def _parse_bad_request(d: Dict[str, Any]) -> BadRequest:
332346
field_violations = []
333347
if "field_violations" in d:
@@ -336,7 +350,7 @@ def _parse_bad_request(d: Dict[str, Any]) -> BadRequest:
336350
for violation in d["field_violations"]:
337351
if not isinstance(violation, dict):
338352
raise ValueError(f"Expected dict, got {violation!r}")
339-
field_violations.append(BadRequestFieldViolation(**violation))
353+
field_violations.append(_parse_bad_request_field_violation(violation))
340354
return BadRequest(field_violations=field_violations)
341355

342356

@@ -349,6 +363,13 @@ def _parse_resource_info(d: Dict[str, Any]) -> ResourceInfo:
349363
)
350364

351365

366+
def _parse_help_link(d: Dict[str, Any]) -> HelpLink:
367+
return HelpLink(
368+
description=_parse_string(d.get("description", "")),
369+
url=_parse_string(d.get("url", "")),
370+
)
371+
372+
352373
def _parse_help(d: Dict[str, Any]) -> Help:
353374
links = []
354375
if "links" in d:
@@ -357,7 +378,7 @@ def _parse_help(d: Dict[str, Any]) -> Help:
357378
for link in d["links"]:
358379
if not isinstance(link, dict):
359380
raise ValueError(f"Expected dict, got {link!r}")
360-
links.append(HelpLink(**link))
381+
links.append(_parse_help_link(link))
361382
return Help(links=links)
362383

363384

0 commit comments

Comments
 (0)