Skip to content

Commit

Permalink
Addressed issue with disabled features in certain regions (databricks…
Browse files Browse the repository at this point in the history
…labs#1618)

## Changes
- Added error handling when listing serving endpoints, as it will raise
NotFound error if the feature is disabled.

### Linked issues
<!-- DOC: Link issue with a keyword: close, closes, closed, fix, fixes,
fixed, resolve, resolves, resolved. See
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->

Resolves databrickslabs#1617


### Tests
<!-- How is this tested? Please see the checklist below and also
describe any other relevant tests -->

- [x] manually tested
- [x] added unit tests
  • Loading branch information
nkvuong authored May 3, 2024
1 parent 32677f5 commit 9ca2d82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/databricks/labs/ucx/workspace_access/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ def object_types(self) -> set[str]:

def __iter__(self):
started = datetime.datetime.now()
for item in self._func():
yield GenericPermissionsInfo(getattr(item, self._id_attribute), self._object_type)
try:
for item in self._func():
yield GenericPermissionsInfo(getattr(item, self._id_attribute), self._object_type)
except NotFound as e:
logger.error(f"Listing {self._object_type} failed: {e}")
since = datetime.datetime.now() - started
logger.info(f"Listed {self._object_type} in {since}")

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/workspace_access/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,3 +916,13 @@ def test_models_page_listing():
for item in auth_items:
assert item.object_id == "/root"
assert item.object_type == "registered-models"


def test_serving_endpoints_not_enabled(caplog):
ws = create_autospec(WorkspaceClient)
ws.serving_endpoints.list.side_effect = NotFound("Model serving is not enabled for your shard")

sup = GenericPermissionsSupport(ws=ws, listings=[Listing(ws.serving_endpoints.list, "id", "serving-endpoints")])
with caplog.at_level('ERROR'):
list(sup.get_crawler_tasks())
assert "Listing serving-endpoints failed: Model serving is not enabled for your shard" in caplog.text

0 comments on commit 9ca2d82

Please sign in to comment.