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

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-4469-829cbb94da728e15ddd5dca7f62cc66b0130fee4
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git

commit c017b204cd61ae42d89a1f11c701ed7e2eaa3d50
Author: Gedalia Kliger <[email protected]>
AuthorDate: Thu Nov 26 16:02:49 2026 +0000

    Reject dropping a SqlCatalog namespace that has child namespaces (#4469)
    
    drop_namespace only checked for tables, so dropping a parent namespace
    deleted its properties and reported success while its children kept it
    listed. Java's JdbcCatalog.dropNamespace throws NamespaceNotEmptyException
    in this case.
---
 pyiceberg/catalog/sql.py                |  3 +++
 tests/catalog/test_catalog_behaviors.py | 13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/pyiceberg/catalog/sql.py b/pyiceberg/catalog/sql.py
index 15e32303b..a72266ace 100644
--- a/pyiceberg/catalog/sql.py
+++ b/pyiceberg/catalog/sql.py
@@ -651,6 +651,9 @@ class SqlCatalog(MetastoreCatalog):
             raise NoSuchNamespaceError(f"Namespace does not exist: 
{namespace}")
 
         namespace_str = Catalog.namespace_to_string(namespace)
+        if child_namespaces := self.list_namespaces(namespace_str):
+            raise NamespaceNotEmptyError(f"Namespace {namespace_str} is not 
empty. {len(child_namespaces)} namespaces exist.")
+
         if tables := self.list_tables(namespace):
             raise NamespaceNotEmptyError(f"Namespace {namespace_str} is not 
empty. {len(tables)} tables exist.")
 
diff --git a/tests/catalog/test_catalog_behaviors.py 
b/tests/catalog/test_catalog_behaviors.py
index a798b56b3..90ba15a19 100644
--- a/tests/catalog/test_catalog_behaviors.py
+++ b/tests/catalog/test_catalog_behaviors.py
@@ -1423,6 +1423,19 @@ def 
test_drop_namespace_raises_error_when_namespace_not_empty(
         catalog.drop_namespace(namespace)
 
 
+def 
test_drop_namespace_raises_error_when_namespace_has_child_namespaces(catalog: 
Catalog, test_namespace: Identifier) -> None:
+    child_namespace = test_namespace + ("child",)
+    catalog.create_namespace(test_namespace)
+    catalog.create_namespace(child_namespace)
+    with pytest.raises(NamespaceNotEmptyError, match=f"Namespace 
{'.'.join(test_namespace)} is not empty. 1 namespaces exist."):
+        catalog.drop_namespace(test_namespace)
+    assert catalog.namespace_exists(test_namespace)
+    assert catalog.namespace_exists(child_namespace)
+    catalog.drop_namespace(child_namespace)
+    catalog.drop_namespace(test_namespace)
+    assert not catalog.namespace_exists(test_namespace)
+
+
 # RecordBatchReader streaming append/overwrite tests
 #
 # Streaming writes accept a pa.RecordBatchReader and microbatch it into 
target-sized

Reply via email to