Skip to content

Commit 2679758

Browse files
Handle InternalError in Listing.__iter__ (#2697)
<!-- REMOVE IRRELEVANT COMMENTS BEFORE CREATING A PULL REQUEST --> ## Changes <!-- Summary of your changes that are easy to understand. Add screenshots when necessary --> ### 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 #2582 ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] manually tested - [x] added unit tests
1 parent 1629eff commit 2679758

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/databricks/labs/ucx/workspace_access/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def __iter__(self):
5959
try:
6060
for item in self._func():
6161
yield GenericPermissionsInfo(getattr(item, self._id_attribute), self._object_type)
62-
except NotFound as e:
63-
logger.warning(f"Listing {self._object_type} failed: {e}")
62+
except (NotFound, InternalError) as e:
63+
logger.warning(f"Listing {self._object_type} failed", exc_info=e)
6464
since = datetime.datetime.now() - started
6565
logger.info(f"Listed {self._object_type} in {since}")
6666

tests/unit/workspace_access/test_generic.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,11 +918,21 @@ def test_models_page_listing():
918918
assert item.object_type == "registered-models"
919919

920920

921-
def test_serving_endpoints_not_enabled_raises_warning(caplog):
921+
def test_serving_endpoints_not_enabled_raises_warning(caplog) -> None:
922922
ws = create_autospec(WorkspaceClient)
923923
ws.serving_endpoints.list.side_effect = NotFound("Model serving is not enabled for your shard")
924924

925925
sup = GenericPermissionsSupport(ws=ws, listings=[Listing(ws.serving_endpoints.list, "id", "serving-endpoints")])
926-
with caplog.at_level('WARNING'):
926+
with caplog.at_level('WARNING', logger="databricks.labs.ucx.workspace_access.generic"):
927927
list(sup.get_crawler_tasks())
928-
assert "Listing serving-endpoints failed: Model serving is not enabled for your shard" in caplog.text
928+
assert "Listing serving-endpoints failed" in caplog.text
929+
930+
931+
def test_internal_error_in_serving_endpoints_raises_warning(caplog) -> None:
932+
ws = create_autospec(WorkspaceClient)
933+
ws.serving_endpoints.list.side_effect = InternalError
934+
935+
sup = GenericPermissionsSupport(ws=ws, listings=[Listing(ws.serving_endpoints.list, "id", "serving-endpoints")])
936+
with caplog.at_level('WARNING', logger="databricks.labs.ucx.workspace_access.generic"):
937+
list(sup.get_crawler_tasks())
938+
assert "Listing serving-endpoints failed" in caplog.text

0 commit comments

Comments
 (0)