diff --git a/pyiceberg/catalog/rest/__init__.py b/pyiceberg/catalog/rest/__init__.py index d085c6fd87..c7e06ef0f3 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -1039,7 +1039,8 @@ def register_table(self, identifier: str | Identifier, metadata_location: str, o @retry(**_RETRY_ARGS) @override def list_tables(self, namespace: str | Identifier) -> list[Identifier]: - self._check_endpoint(Capability.V1_LIST_TABLES) + if Capability.V1_LIST_TABLES not in self._supported_endpoints: + return [] namespace_tuple = self._check_valid_namespace_identifier(namespace) namespace_concat = self._encode_namespace_path(namespace_tuple) url = self.url(Endpoints.list_tables, namespace=namespace_concat) @@ -1277,7 +1278,8 @@ def drop_namespace(self, namespace: str | Identifier) -> None: @retry(**_RETRY_ARGS) @override def list_namespaces(self, namespace: str | Identifier = ()) -> list[Identifier]: - self._check_endpoint(Capability.V1_LIST_NAMESPACES) + if Capability.V1_LIST_NAMESPACES not in self._supported_endpoints: + return [] namespace_tuple = self.identifier_to_tuple(namespace) params: dict[str, str] = {} diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py index 691e163744..270512ae5c 100644 --- a/tests/catalog/test_rest.py +++ b/tests/catalog/test_rest.py @@ -2887,6 +2887,34 @@ def test_unsupported_endpoint(self, requests_mock: Mocker) -> None: with pytest.raises(NotImplementedError, match="Server does not support endpoint"): catalog._check_endpoint(Capability.V1_LIST_TABLES) + def test_list_tables_returns_empty_when_unsupported(self, requests_mock: Mocker) -> None: + requests_mock.get( + f"{TEST_URI}v1/config", + json={ + "defaults": {}, + "overrides": {}, + "endpoints": ["GET /v1/{prefix}/namespaces"], + }, + status_code=200, + ) + catalog = RestCatalog("rest", uri=TEST_URI, token="token") + + assert catalog.list_tables(("examples",)) == [] + + def test_list_namespaces_returns_empty_when_unsupported(self, requests_mock: Mocker) -> None: + requests_mock.get( + f"{TEST_URI}v1/config", + json={ + "defaults": {}, + "overrides": {}, + "endpoints": ["GET /v1/{prefix}/namespaces/{namespace}/tables"], + }, + status_code=200, + ) + catalog = RestCatalog("rest", uri=TEST_URI, token="token") + + assert catalog.list_namespaces() == [] + def test_config_returns_invalid_endpoint(self, requests_mock: Mocker) -> None: requests_mock.get( f"{TEST_URI}v1/config",