You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ho...@apache.org on 2024/07/04 06:05:43 UTC

(iceberg-python) branch main updated: Handle error when trying to drop a non-empty namespace on rest.py (#868)

This is an automated email from the ASF dual-hosted git repository.

honahx pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new a8d3f17d Handle error when trying to drop a non-empty namespace on rest.py (#868)
a8d3f17d is described below

commit a8d3f17d42b00b507a3522714fe431a18124493e
Author: edson duarte <ed...@gmail.com>
AuthorDate: Thu Jul 4 03:05:39 2024 -0300

    Handle error when trying to drop a non-empty namespace on rest.py (#868)
---
 pyiceberg/catalog/rest.py  |  3 ++-
 tests/catalog/test_rest.py | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py
index 2474b898..20d28cb2 100644
--- a/pyiceberg/catalog/rest.py
+++ b/pyiceberg/catalog/rest.py
@@ -47,6 +47,7 @@ from pyiceberg.exceptions import (
     CommitStateUnknownException,
     ForbiddenError,
     NamespaceAlreadyExistsError,
+    NamespaceNotEmptyError,
     NoSuchNamespaceError,
     NoSuchTableError,
     OAuthError,
@@ -725,7 +726,7 @@ class RestCatalog(Catalog):
         try:
             response.raise_for_status()
         except HTTPError as exc:
-            self._handle_non_200_response(exc, {404: NoSuchNamespaceError})
+            self._handle_non_200_response(exc, {404: NoSuchNamespaceError, 409: NamespaceNotEmptyError})
 
     @retry(**_RETRY_ARGS)
     def list_namespaces(self, namespace: Union[str, Identifier] = ()) -> List[Identifier]:
diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py
index b5c626d6..2ddc774b 100644
--- a/tests/catalog/test_rest.py
+++ b/tests/catalog/test_rest.py
@@ -28,6 +28,7 @@ from pyiceberg.catalog.rest import AUTH_URL, RestCatalog
 from pyiceberg.exceptions import (
     AuthorizationExpiredError,
     NamespaceAlreadyExistsError,
+    NamespaceNotEmptyError,
     NoSuchNamespaceError,
     NoSuchTableError,
     OAuthError,
@@ -556,6 +557,25 @@ def test_drop_namespace_404(rest_mock: Mocker) -> None:
     assert "Namespace does not exist" in str(e.value)
 
 
+def test_drop_namespace_409(rest_mock: Mocker) -> None:
+    namespace = "examples"
+    rest_mock.delete(
+        f"{TEST_URI}v1/namespaces/{namespace}",
+        json={
+            "error": {
+                "message": "Namespace is not empty: leden in warehouse 8bcb0838-50fc-472d-9ddb-8feb89ef5f1e",
+                "type": "NamespaceNotEmptyError",
+                "code": 409,
+            }
+        },
+        status_code=409,
+        request_headers=TEST_HEADERS,
+    )
+    with pytest.raises(NamespaceNotEmptyError) as e:
+        RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).drop_namespace(namespace)
+    assert "Namespace is not empty" in str(e.value)
+
+
 def test_load_namespace_properties_200(rest_mock: Mocker) -> None:
     namespace = "leden"
     rest_mock.get(