Skip to content

Commit c5735dc

Browse files
authored
raise exception if namespace does not exist in load_namespace_properties (#477)
1 parent 5209874 commit c5735dc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pyiceberg/catalog/sql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,9 @@ def load_namespace_properties(self, namespace: Union[str, Identifier]) -> Proper
567567
Raises:
568568
NoSuchNamespaceError: If a namespace with the given name does not exist.
569569
"""
570-
database_name = self.identifier_to_database(namespace, NoSuchNamespaceError)
570+
database_name = self.identifier_to_database(namespace)
571+
if not self._namespace_exists(database_name):
572+
raise NoSuchNamespaceError(f"Database {database_name} does not exists")
571573

572574
stmt = select(IcebergNamespaceProperties).where(
573575
IcebergNamespaceProperties.catalog_name == self.name, IcebergNamespaceProperties.namespace == database_name

tests/catalog/test_sql.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,18 @@ def test_load_empty_namespace_properties(catalog: SqlCatalog, database_name: str
726726
assert listed_properties == {"exists": "true"}
727727

728728

729+
@pytest.mark.parametrize(
730+
'catalog',
731+
[
732+
lazy_fixture('catalog_memory'),
733+
lazy_fixture('catalog_sqlite'),
734+
],
735+
)
736+
def test_load_namespace_properties_non_existing_namespace(catalog: SqlCatalog) -> None:
737+
with pytest.raises(NoSuchNamespaceError):
738+
catalog.load_namespace_properties("does_not_exist")
739+
740+
729741
@pytest.mark.parametrize(
730742
'catalog',
731743
[

0 commit comments

Comments
 (0)