diff --git a/pyiceberg/catalog/sql.py b/pyiceberg/catalog/sql.py index a72266ace4..d2c34a692e 100644 --- a/pyiceberg/catalog/sql.py +++ b/pyiceberg/catalog/sql.py @@ -781,9 +781,9 @@ def update_namespace_properties( raise NoSuchNamespaceError(f"Namespace {namespace_str} does not exists") current_properties = self.load_namespace_properties(namespace=namespace) - properties_update_summary = self._get_updated_props_and_update_summary( + properties_update_summary, updated_properties = self._get_updated_props_and_update_summary( current_properties=current_properties, removals=removals, updates=updates - )[0] + ) with Session(self.engine) as session: if removals: @@ -815,6 +815,18 @@ def update_namespace_properties( ] insert_stmt = insert(IcebergNamespaceProperties).values(insert_stmt_values) session.execute(insert_stmt) + + if properties_update_summary.removed and not updated_properties: + # A namespace without tables only exists through its properties + for key, value in IcebergNamespaceProperties.NAMESPACE_MINIMAL_PROPERTIES.items(): + session.add( + IcebergNamespaceProperties( + catalog_name=self.name, + namespace=namespace_str, + property_key=key, + property_value=value, + ) + ) session.commit() return properties_update_summary diff --git a/tests/catalog/test_catalog_behaviors.py b/tests/catalog/test_catalog_behaviors.py index 90ba15a197..4e43be5746 100644 --- a/tests/catalog/test_catalog_behaviors.py +++ b/tests/catalog/test_catalog_behaviors.py @@ -1359,6 +1359,15 @@ def test_update_namespace_properties(catalog: Catalog, test_namespace: Identifie } +def test_update_namespace_properties_removes_all_properties(catalog: Catalog, test_namespace: Identifier) -> None: + catalog.create_namespace(test_namespace, {"comment": "this is a test description"}) + update_report = catalog.update_namespace_properties(test_namespace, removals={"comment"}) + assert update_report.removed == ["comment"] + assert catalog.namespace_exists(test_namespace) + assert test_namespace in catalog.list_namespaces(test_namespace[:-1]) + assert catalog.load_namespace_properties(test_namespace) == {"exists": "true"} + + def test_update_namespace_metadata_raises_error_when_namespace_does_not_exist( catalog: Catalog, test_namespace: Identifier, test_table_properties: dict[str, str] ) -> None: