databricks / databricks-sdk-py

Databricks SDK for Python (Beta)
https://databricks-sdk-py.readthedocs.io/
Apache License 2.0
346 stars 114 forks source link

[ISSUE] Fix 403 deserialization issue in service_principals.get() method #768

Open kishaningithub opened 1 day ago

kishaningithub commented 1 day ago

Description

When calling the service_principals.get() with a valid service principal id the request failed with the following error

Traceback (most recent call last):
  File "/home/test/app/hello.py", line 23, in <module>
    main()
  File "/home/test/app/hello.py", line 18, in main
    details = client.service_principals.get(service_principal.id)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/test/app/.venv/lib/python3.12/site-packages/databricks/sdk/service/iam.py", line 2792, in get
    res = self._api.do('GET', f'/api/2.0/preview/scim/v2/ServicePrincipals/{id}', headers=headers)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/test/app/.venv/lib/python3.12/site-packages/databricks/sdk/core.py", line 157, in do
    response = retryable(self._perform)(method,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/test/app/.venv/lib/python3.12/site-packages/databricks/sdk/retries.py", line 54, in wrapper
    raise err
  File "/home/test/app/.venv/lib/python3.12/site-packages/databricks/sdk/retries.py", line 33, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/test/app/.venv/lib/python3.12/site-packages/databricks/sdk/core.py", line 247, in _perform
    raise error from None
databricks.sdk.errors.platform.PermissionDenied: unable to parse response. This is likely a bug in the Databricks SDK for Python or the underlying API. Please report this issue with the following debugging information to the SDK issue tracker at https://github.com/databricks/databricks-sdk-go/issues. Request log:```GET /api/2.0/preview/scim/v2/ServicePrincipals/6671074037673577
> * User-Agent: unknown/0.0.0 databricks-sdk-py/0.32.2 python/3.12.6 os/darwin auth/pat
> * Accept-Encoding: gzip, deflate
> * Accept: application/json
> * Connection: keep-alive
> * Authorization: Bearer REDACTED_TOKEN
< 403 Forbidden
< https://<<READACTED>>.cloud.databricks.com/api/2.0/preview/scim/v2/ServicePrincipals/6671074037673577 is only accessible by admins.```

Reproduction A minimal code sample demonstrating the bug.

import json
from databricks.sdk import WorkspaceClient

def main():
    host = "<<databricks host>>"
    token = "<<token>>"
    client = WorkspaceClient(host=host, token=token)

    id = client.service_principals.list()[0].id
   details = client.service_principals.get(id)
   print(json.dumps(details.as_dict()))

if __name__ == "__main__":
    main()

Expected behavior

  1. The failure "unable to parse response" should not have occurred
  2. The url pointed by the error message should point to this library and not the golang version of the same

Is it a regression? Did this work in a previous version of the SDK? If so, which versions did you try? No

Other Information

kishaningithub commented 1 day ago
  1. The url pointed by the error message should point to this library and not the golang version of the same

Have fixed the above expected behavior in PR https://github.com/databricks/databricks-sdk-py/pull/767

mgyucht commented 22 hours ago

@kishaningithub please revoke the bearer token you've included in the issue description and remove it from the description when done.

kishaningithub commented 22 hours ago

Done @mgyucht Thanks for the callout