Skip to content

Commit a8d3f17

Browse files
authored
Handle error when trying to drop a non-empty namespace on rest.py (#868)
1 parent 1b92851 commit a8d3f17

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pyiceberg/catalog/rest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
CommitStateUnknownException,
4848
ForbiddenError,
4949
NamespaceAlreadyExistsError,
50+
NamespaceNotEmptyError,
5051
NoSuchNamespaceError,
5152
NoSuchTableError,
5253
OAuthError,
@@ -725,7 +726,7 @@ def drop_namespace(self, namespace: Union[str, Identifier]) -> None:
725726
try:
726727
response.raise_for_status()
727728
except HTTPError as exc:
728-
self._handle_non_200_response(exc, {404: NoSuchNamespaceError})
729+
self._handle_non_200_response(exc, {404: NoSuchNamespaceError, 409: NamespaceNotEmptyError})
729730

730731
@retry(**_RETRY_ARGS)
731732
def list_namespaces(self, namespace: Union[str, Identifier] = ()) -> List[Identifier]:

tests/catalog/test_rest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from pyiceberg.exceptions import (
2929
AuthorizationExpiredError,
3030
NamespaceAlreadyExistsError,
31+
NamespaceNotEmptyError,
3132
NoSuchNamespaceError,
3233
NoSuchTableError,
3334
OAuthError,
@@ -556,6 +557,25 @@ def test_drop_namespace_404(rest_mock: Mocker) -> None:
556557
assert "Namespace does not exist" in str(e.value)
557558

558559

560+
def test_drop_namespace_409(rest_mock: Mocker) -> None:
561+
namespace = "examples"
562+
rest_mock.delete(
563+
f"{TEST_URI}v1/namespaces/{namespace}",
564+
json={
565+
"error": {
566+
"message": "Namespace is not empty: leden in warehouse 8bcb0838-50fc-472d-9ddb-8feb89ef5f1e",
567+
"type": "NamespaceNotEmptyError",
568+
"code": 409,
569+
}
570+
},
571+
status_code=409,
572+
request_headers=TEST_HEADERS,
573+
)
574+
with pytest.raises(NamespaceNotEmptyError) as e:
575+
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).drop_namespace(namespace)
576+
assert "Namespace is not empty" in str(e.value)
577+
578+
559579
def test_load_namespace_properties_200(rest_mock: Mocker) -> None:
560580
namespace = "leden"
561581
rest_mock.get(

0 commit comments

Comments
 (0)