databricks / databricks-sdk-py

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

Issue when list_webhooks() is called #313

Open Dhanunjaya-Elluri opened 10 months ago

Dhanunjaya-Elluri commented 10 months ago

In the below code, I created a webhook, with the events I'm interested in while creating. However, when I try to list the webhooks, the following error occurs:

code snippet

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import ml

dbx_client = WorkspaceClient(
    host="https://adb-xxx.12.azuredatabricks.net",
)

# Create webhook
webhook = dbx_client.model_registry.create_webhook(
    events=[
        ml.RegistryWebhookEvent.MODEL_VERSION_CREATED,
        ml.RegistryWebhookEvent.MODEL_VERSION_TRANSITIONED_STAGE,
    ],
    model_name="my-model",
    description="Sample model",
    http_url_spec=ml.HttpUrlSpec(
        url="https://app.azurewebsites.net/v1/deployments"
    ),
)

# List webhooks
webhooks = dbx_client.model_registry.list_webhooks(model_name="my-model") 
output = [webhook.as_dict() for webhook in webhooks] 
print(output)

Error:

Traceback (most recent call last):
  File "C:\Users\jay\PycharmProjects\feature-branches\api-test\playground\main.py", line 56, in <module>
    output = [
  File "C:\Users\jay\PycharmProjects\feature-branches\api-test\playground\main.py", line 57, in <listcomp>
    webhook.as_dict() for webhook in webhooks
  File "C:\Program Files (x86)\conda3_2022\envs\py310\lib\site-packages\databricks\sdk\service\ml.py", line 1600, in as_dict   
    if self.events: body['events'] = [v.value for v in self.events]
  File "C:\Program Files (x86)\conda3_2022\envs\py310\lib\site-packages\databricks\sdk\service\ml.py", line 1600, in <listcomp>
    if self.events: body['events'] = [v.value for v in self.events]
AttributeError: 'str' object has no attribute 'value'

My interpretation is that the events are registered as strings rather than enums.

Fix: databricks-sdk-py/databricks/sdk/service /ml.py

Line 1600

if self.events: body['events'] = self.events

This works for me. Please fix this issue :)

Additional Information:

Python version: 3.10 Databricks SDK version: databricks-sdk==0.6.0

mgyucht commented 10 months ago

Thanks for raising this issue! We don't really exercise the .as_dict() method on response objects, as we are typically only deserializing them and not serializing them. We should be able to fix this in generated code.

sh0rtcircuit commented 10 months ago

I am facing the same issue, it would be great if this could be adressed! 😊