This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-4415-a1a4f77b1a18c4dc9f3265377e1d1fbed644c77e
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git

commit 8f6ea309f5a0e6bfea8dcfe50e2f45702e0753a2
Author: Faris Basha TM <[email protected]>
AuthorDate: Wed Nov 18 21:17:17 2026 +0000

    Fix the BigQuery namespace-exists error message (#4415)
    
    The message was a plain string, so it showed the literal
    "{database_name}" instead of the namespace name. Make it an f-string
    and add a test for create_namespace on an existing dataset.
---
 pyiceberg/catalog/bigquery_metastore.py  |  2 +-
 tests/catalog/test_bigquery_metastore.py | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/pyiceberg/catalog/bigquery_metastore.py 
b/pyiceberg/catalog/bigquery_metastore.py
index 74d1c952b..9b229ba0d 100644
--- a/pyiceberg/catalog/bigquery_metastore.py
+++ b/pyiceberg/catalog/bigquery_metastore.py
@@ -178,7 +178,7 @@ class BigQueryMetastoreCatalog(MetastoreCatalog):
             dataset.external_catalog_dataset_options = 
self._create_external_catalog_dataset_options(properties, dataset_ref)
             self.client.create_dataset(dataset)
         except Conflict as e:
-            raise NamespaceAlreadyExistsError("Namespace {database_name} 
already exists") from e
+            raise NamespaceAlreadyExistsError(f"Namespace {database_name} 
already exists") from e
 
     @override
     def load_table(self, identifier: str | Identifier) -> Table:
diff --git a/tests/catalog/test_bigquery_metastore.py 
b/tests/catalog/test_bigquery_metastore.py
index df40417ff..4b4f283f5 100644
--- a/tests/catalog/test_bigquery_metastore.py
+++ b/tests/catalog/test_bigquery_metastore.py
@@ -18,13 +18,13 @@ import os
 from unittest.mock import MagicMock
 
 import pytest
-from google.api_core.exceptions import NotFound
+from google.api_core.exceptions import Conflict, NotFound
 from google.cloud.bigquery import Dataset, DatasetReference, Table, 
TableReference
 from google.cloud.bigquery.external_config import 
ExternalCatalogDatasetOptions, ExternalCatalogTableOptions
 from pytest_mock import MockFixture
 
 from pyiceberg.catalog.bigquery_metastore import ICEBERG_TABLE_TYPE_VALUE, 
TABLE_TYPE_PROP, BigQueryMetastoreCatalog
-from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchTableError
+from pyiceberg.exceptions import NamespaceAlreadyExistsError, 
NoSuchNamespaceError, NoSuchTableError
 from pyiceberg.schema import Schema
 
 
@@ -124,6 +124,19 @@ def test_drop_namespace(mocker: MockFixture, 
gcp_dataset_name: str) -> None:
     assert args[0].dataset_id == gcp_dataset_name
 
 
+def test_create_namespace_already_exists(mocker: MockFixture, 
gcp_dataset_name: str) -> None:
+    client_mock = MagicMock()
+    client_mock.create_dataset.side_effect = Conflict("Already Exists")
+    mocker.patch("pyiceberg.catalog.bigquery_metastore.Client", 
return_value=client_mock)
+    mocker.patch.dict(os.environ, 
values={"PYICEBERG_LEGACY_CURRENT_SNAPSHOT_ID": "True"})
+    catalog = BigQueryMetastoreCatalog(
+        "test_catalog", **{"gcp.bigquery.project-id": "my-project", 
"warehouse": "gs://test-bucket/warehouse"}
+    )
+
+    with pytest.raises(NamespaceAlreadyExistsError, match=f"^Namespace 
{gcp_dataset_name} already exists$"):
+        catalog.create_namespace(gcp_dataset_name)
+
+
 def test_list_tables(mocker: MockFixture, gcp_dataset_name: str) -> None:
     client_mock = MagicMock()
 

Reply via email to