Skip to content

Commit

Permalink
Fix deserialization of repeated enums
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyucht committed Nov 20, 2023
1 parent 86ca043 commit e7bfb05
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 344 deletions.
7 changes: 4 additions & 3 deletions .codegen/service.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import time
import random
import logging
from ..errors import OperationTimeout, OperationFailed
from ._internal import _enum, _from_dict, _repeated, Wait
from ._internal import _enum, _from_dict, _repeated_dict, _repeated_enum, Wait

_LOG = logging.getLogger('databricks.sdk')

Expand Down Expand Up @@ -45,8 +45,9 @@ class {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:{{if .Descriptio
{{- define "from_dict_type" -}}
{{- if not .Entity }}None
{{- else if .Entity.ArrayValue }}
{{- if .Entity.ArrayValue.IsObject }}_repeated(d, '{{.Name}}', {{template "type-nq" .Entity.ArrayValue}})
{{- else if .Entity.ArrayValue.IsExternal }}_repeated(d, '{{.Name}}', {{template "type-nq" .Entity.ArrayValue}})
{{- if .Entity.ArrayValue.IsObject }}_repeated_dict(d, '{{.Name}}', {{template "type-nq" .Entity.ArrayValue}})
{{- else if .Entity.ArrayValue.IsExternal }}_repeated_dict(d, '{{.Name}}', {{.Entity.Package.Name}}.{{template "type-nq" .Entity.ArrayValue}})
{{- else if .Entity.ArrayValue.Enum }}_repeated_enum(d, '{{.Name}}', {{template "type-nq" .Entity.ArrayValue}})
{{- else}}d.get('{{.Name}}', None){{- end -}}
{{- else if .Entity.IsObject }}_from_dict(d, '{{.Name}}', {{.Entity.PascalName}})
{{- else if .Entity.IsExternal }}_from_dict(d, '{{.Name}}', {{.Entity.Package.Name}}.{{.Entity.PascalName}})
Expand Down
8 changes: 7 additions & 1 deletion databricks/sdk/service/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def _from_dict(d: Dict[str, any], field: str, cls: Type) -> any:
return getattr(cls, 'from_dict')(d[field])


def _repeated(d: Dict[str, any], field: str, cls: Type) -> any:
def _repeated_dict(d: Dict[str, any], field: str, cls: Type) -> any:
if field not in d or not d[field]:
return None
from_dict = getattr(cls, 'from_dict')
Expand All @@ -21,6 +21,12 @@ def _enum(d: Dict[str, any], field: str, cls: Type) -> any:
return next((v for v in getattr(cls, '__members__').values() if v.value == d[field]), None)


def _repeated_enum(d: Dict[str, any], field: str, cls: Type) -> any:
if field not in d or not d[field]:
return None
return [next((v for v in getattr(cls, '__members__').values() if v.value == e), None) for e in d[field]]


ReturnType = TypeVar('ReturnType')


Expand Down
14 changes: 7 additions & 7 deletions databricks/sdk/service/billing.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 35 additions & 31 deletions databricks/sdk/service/catalog.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e7bfb05

Please sign in to comment.