Skip to content

Commit

Permalink
raise exception if namespace does not exist in load_namespace_propert…
Browse files Browse the repository at this point in the history
…ies (#477)
  • Loading branch information
rushilshah1 authored Feb 27, 2024
1 parent 5209874 commit c5735dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pyiceberg/catalog/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ def load_namespace_properties(self, namespace: Union[str, Identifier]) -> Proper
Raises:
NoSuchNamespaceError: If a namespace with the given name does not exist.
"""
database_name = self.identifier_to_database(namespace, NoSuchNamespaceError)
database_name = self.identifier_to_database(namespace)
if not self._namespace_exists(database_name):
raise NoSuchNamespaceError(f"Database {database_name} does not exists")

stmt = select(IcebergNamespaceProperties).where(
IcebergNamespaceProperties.catalog_name == self.name, IcebergNamespaceProperties.namespace == database_name
Expand Down
12 changes: 12 additions & 0 deletions tests/catalog/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,18 @@ def test_load_empty_namespace_properties(catalog: SqlCatalog, database_name: str
assert listed_properties == {"exists": "true"}


@pytest.mark.parametrize(
'catalog',
[
lazy_fixture('catalog_memory'),
lazy_fixture('catalog_sqlite'),
],
)
def test_load_namespace_properties_non_existing_namespace(catalog: SqlCatalog) -> None:
with pytest.raises(NoSuchNamespaceError):
catalog.load_namespace_properties("does_not_exist")


@pytest.mark.parametrize(
'catalog',
[
Expand Down

0 comments on commit c5735dc

Please sign in to comment.