Problem
You are attempting to programmatically update tags for a serving endpoint using the Python SDK on any cluster. When you use the w.serving_endpoints.patch()
call you receive the following error.
AttributeError: 'str' object has no attribute 'get'
Cause
The default databricks-sdk
version (0.20.0) pre-installed on compute lacks complete implementation of the patch()
method for serving endpoints. While the method is present, it does not correctly handle the API response format returned, leading to failures when attempting to update tags.
Solution
Upgrade the databricks-sdk
to version 0.53.0 or above.
!pip install --upgrade databricks-sdk
dbutils.library.restartPython()
After upgrading, use the EndpointTag
class to define tags and pass them to the add_tags
parameter in the patch()
method of the serving_endpoints
client.
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import EndpointTag
w = WorkspaceClient()
tags_to_add = [
EndpointTag(key="<endpoint-key>", value="<endpoint-value>"),
EndpointTag(key="<endpoint-key>", value="<endpoint-value>"),
]
updated_tags = w.serving_endpoints.patch(
name="<serving-endpoint-name>",
add_tags=tags_to_add,
)
print("Endpoint now has these tags:", updated_tags)
For more information on the patch()
method, review the w.serving_endpoints: Serving endpoints documentation.