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-4301-0b8b26a8992fd04a0372875795347a1cf4a24ee7
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git

commit 7864d4c34e90711da363041bc5de4bdeff777823
Author: chenjian2664 <[email protected]>
AuthorDate: Fri Nov 27 09:57:43 2026 +0000

    Read py-catalog-impl from the catalog configuration (#4301)
    
    load_catalog only looked for py-catalog-impl in its keyword arguments, so
    the documented .pyiceberg.yaml and PYICEBERG_CATALOG__* settings were
    ignored and loading failed with "URI missing". When the implementation was
    passed as an argument, the custom catalog also lost the properties from the
    configuration. Read it from the merged configuration and pass that
    configuration to the custom catalog.
    
    test_missing_uri patched the configuration with a MagicMock rather than a
    Config, so it now patches an empty Config again.
---
 pyiceberg/catalog/__init__.py |  4 ++--
 tests/catalog/test_base.py    | 13 +++++++++++++
 tests/cli/test_console.py     |  4 ++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/pyiceberg/catalog/__init__.py b/pyiceberg/catalog/__init__.py
index 1c063cb52..5af504f8a 100644
--- a/pyiceberg/catalog/__init__.py
+++ b/pyiceberg/catalog/__init__.py
@@ -304,14 +304,14 @@ def load_catalog(name: str | None = None, **properties: 
str | None) -> Catalog:
     catalog_type: CatalogType | None
     provided_catalog_type = conf.get(TYPE)
 
-    if catalog_impl := properties.get(PY_CATALOG_IMPL):
+    if catalog_impl := conf.get(PY_CATALOG_IMPL):
         if provided_catalog_type:
             raise ValueError(
                 "Must not set both catalog type and py-catalog-impl 
configurations, "
                 f"but found type {provided_catalog_type} and py-catalog-impl 
{catalog_impl}"
             )
 
-        if catalog := _import_catalog(name, catalog_impl, properties):
+        if catalog := _import_catalog(name, cast(str, catalog_impl), 
cast(dict[str, str], conf)):
             logger.info("Loaded Catalog: %s", catalog_impl)
             return catalog
         else:
diff --git a/tests/catalog/test_base.py b/tests/catalog/test_base.py
index 1a4747831..8e1891a90 100644
--- a/tests/catalog/test_base.py
+++ b/tests/catalog/test_base.py
@@ -21,6 +21,7 @@ from collections.abc import Generator
 from pathlib import PosixPath
 
 import pytest
+from pytest_mock import MockerFixture
 
 from pyiceberg.catalog import Catalog, load_catalog
 from pyiceberg.catalog.memory import InMemoryCatalog
@@ -54,6 +55,18 @@ def test_load_catalog_impl_does_not_exist() -> None:
     assert "Could not initialize Catalog: pyiceberg.does.not.exist.Catalog" in 
str(exc_info.value)
 
 
+def test_load_catalog_impl_from_config(mocker: MockerFixture) -> None:
+    mocker.patch(
+        "pyiceberg.catalog._ENV_CONFIG.get_catalog_config",
+        return_value={"py-catalog-impl": 
"pyiceberg.catalog.memory.InMemoryCatalog", "test.key": "test.value"},
+    )
+
+    catalog = load_catalog("catalog")
+
+    assert isinstance(catalog, InMemoryCatalog)
+    assert catalog.properties["test.key"] == "test.value"
+
+
 def test_load_catalog_has_type_and_impl() -> None:
     with pytest.raises(ValueError) as exc_info:
         load_catalog("catalog", **{"py-catalog-impl": 
"pyiceberg.does.not.exist.Catalog", "type": "sql"})
diff --git a/tests/cli/test_console.py b/tests/cli/test_console.py
index ebf1a5a90..669c3faa9 100644
--- a/tests/cli/test_console.py
+++ b/tests/cli/test_console.py
@@ -44,13 +44,13 @@ from pyiceberg.view.metadata import ViewMetadata
 def test_missing_uri(mocker: MockFixture, empty_home_dir_path: str) -> None:
     # mock to prevent parsing ~/.pyiceberg.yaml or 
{PYICEBERG_HOME}/.pyiceberg.yaml
     mocker.patch.dict(os.environ, values={"HOME": empty_home_dir_path, 
"PYICEBERG_HOME": empty_home_dir_path})
-    mocker.patch("pyiceberg.catalog._ENV_CONFIG", return_value=Config())
+    mocker.patch("pyiceberg.catalog._ENV_CONFIG", Config())
 
     runner = CliRunner()
     result = runner.invoke(run, ["list"])
 
     assert result.exit_code == 1
-    assert result.output == "Could not initialize catalog with the following 
properties: {}\n"
+    assert "URI missing, please provide using --uri" in result.output
 
 
 def test_hive_catalog_missing_uri_shows_helpful_error(mocker: MockFixture) -> 
None:

Reply via email to