Skip to content

[ISSUE] iam.User.as_dict() raises error in 0.11.0+ sdk #449

@grusin-db

Description

@grusin-db

Description
I’ve noticed that iam.User.as_dict() is throwing errors in python sdk 0.11.0+ (it worked in 0.10.0):
example code:

Reproduction

def test_dbr_sdk():
    c = AccountClient(account_id="aaaaa-bbbb-cccc-dddd", host='https://accounts.azuredatabricks.net/')
    g = c.users.get(6798941285817267)
    print(g)
    # crashes below
    d = g.as_dict()
    print(d)

error:

./pytests/self_check_test.py::test_dbr_sdk Failed: [undefined]AttributeError: 'str' object has no attribute 'value'
def test_dbr_sdk():
     c = AccountClient(account_id="aaaaa-bbbb-cccc-dddd"", host='https://accounts.azuredatabricks.net/')
     g = c.users.get(6798941285817267)
     print(g)
>    d = g.as_dict()

pytests\self_check_test.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\AppData\Roaming\Python\Python310\site-packages\databricks\sdk\service\iam.py:832: in as_dict
   if self.schemas: body['schemas'] = [v.value for v in self.schemas]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

.0 = <list_iterator object at 0x0000023EEEA983D0>

>  if self.schemas: body['schemas'] = [v.value for v in self.schemas]
E  AttributeError: 'str' object has no attribute 'value'

Expected behavior
it should give back dict, as it used to

Is it a regression?
yes, issue is related to iam.User.schemas being recently added to SDK. Now when User object is created from API response, schemas is a string (see User.from_dict(...) just takes a value without sanitising it), while the Enum is expected, code is here: https://github.com/databricks/databricks-sdk-py/blame/main/databricks/sdk/service/iam.py#L832

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions