From ffbeceea85f520758fd181c77648f828576b7f84 Mon Sep 17 00:00:00 2001 From: mj006648 Date: Mon, 3 Aug 2026 07:41:29 +0000 Subject: [PATCH] Fix empty CLI property lookup --- pyiceberg/cli/console.py | 6 ++++-- tests/cli/test_console.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pyiceberg/cli/console.py b/pyiceberg/cli/console.py index 3feed9fb21..940a9f0282 100644 --- a/pyiceberg/cli/console.py +++ b/pyiceberg/cli/console.py @@ -327,7 +327,8 @@ def get_namespace(ctx: Context, identifier: str, property_name: str) -> None: namespace_properties = catalog.load_namespace_properties(identifier_tuple) if property_name: - if property_value := namespace_properties.get(property_name): + property_value = namespace_properties.get(property_name) + if property_value is not None: output.text(property_value) else: raise NoSuchPropertyException(f"Could not find property {property_name} on namespace {identifier}") @@ -348,7 +349,8 @@ def get_table(ctx: Context, identifier: str, property_name: str) -> None: metadata = catalog.load_table(identifier_tuple).metadata if property_name: - if property_value := metadata.properties.get(property_name): + property_value = metadata.properties.get(property_name) + if property_value is not None: output.text(property_value) else: raise NoSuchPropertyException(f"Could not find property {property_name} on table {identifier}") diff --git a/tests/cli/test_console.py b/tests/cli/test_console.py index 27a1bfebe4..408e369f73 100644 --- a/tests/cli/test_console.py +++ b/tests/cli/test_console.py @@ -440,6 +440,21 @@ def test_properties_get_table_specific_property(catalog: InMemoryCatalog) -> Non assert result.output == "134217728\n" +def test_properties_get_table_specific_empty_property(catalog: InMemoryCatalog) -> None: + catalog.create_namespace(TEST_TABLE_NAMESPACE) + catalog.create_table( + identifier=TEST_TABLE_IDENTIFIER, + schema=TEST_TABLE_SCHEMA, + partition_spec=TEST_TABLE_PARTITION_SPEC, + properties={"empty": ""}, + ) + + runner = CliRunner() + result = runner.invoke(run, ["properties", "get", "table", "default.my_table", "empty"]) + assert result.exit_code == 0 + assert result.output == "\n" + + def test_properties_get_table_specific_property_that_doesnt_exist(catalog: InMemoryCatalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) catalog.create_table( @@ -482,6 +497,15 @@ def test_properties_get_namespace_specific_property(catalog: InMemoryCatalog, na assert result.output == "s3://warehouse/database/location\n" +def test_properties_get_namespace_specific_empty_property(catalog: InMemoryCatalog) -> None: + catalog.create_namespace(TEST_TABLE_NAMESPACE, {"empty": ""}) + + runner = CliRunner() + result = runner.invoke(run, ["properties", "get", "namespace", "default", "empty"]) + assert result.exit_code == 0 + assert result.output == "\n" + + def test_properties_get_namespace_does_not_exist(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties)