From 473d28d274b7f1213da144ee75dda6f248e237c0 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 3 Jul 2024 23:02:57 -0700 Subject: [PATCH] fix: update all namespace properties in update_namespace_properties (#873) --- pyiceberg/catalog/sql.py | 15 ++++++++++----- tests/catalog/test_sql.py | 7 ++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pyiceberg/catalog/sql.py b/pyiceberg/catalog/sql.py index ff7831d77f..d3cd8a9464 100644 --- a/pyiceberg/catalog/sql.py +++ b/pyiceberg/catalog/sql.py @@ -673,11 +673,16 @@ def update_namespace_properties( IcebergNamespaceProperties.property_key.in_(set(updates.keys())), ) session.execute(delete_stmt) - insert_stmt = insert(IcebergNamespaceProperties) - for property_key, property_value in updates.items(): - insert_stmt = insert_stmt.values( - catalog_name=self.name, namespace=namespace_str, property_key=property_key, property_value=property_value - ) + insert_stmt_values = [ + { + IcebergNamespaceProperties.catalog_name: self.name, + IcebergNamespaceProperties.namespace: namespace_str, + IcebergNamespaceProperties.property_key: property_key, + IcebergNamespaceProperties.property_value: property_value, + } + for property_key, property_value in updates.items() + ] + insert_stmt = insert(IcebergNamespaceProperties).values(insert_stmt_values) session.execute(insert_stmt) session.commit() return properties_update_summary diff --git a/tests/catalog/test_sql.py b/tests/catalog/test_sql.py index 24adfb88ab..eae0c5ea4b 100644 --- a/tests/catalog/test_sql.py +++ b/tests/catalog/test_sql.py @@ -1172,7 +1172,12 @@ def test_update_namespace_properties(catalog: SqlCatalog, namespace: str) -> Non assert k in update_report.missing else: assert k in update_report.removed - assert "updated test description" == catalog.load_namespace_properties(namespace)["comment"] + assert catalog.load_namespace_properties(namespace) == { + "comment": "updated test description", + "test_property4": "4", + "test_property5": "5", + "location": f"{warehouse_location}/{namespace}.db", + } @pytest.mark.parametrize(