From e96b589ddf58e0240e7c26aaf3c1d393fdb42450 Mon Sep 17 00:00:00 2001 From: Koen Denecker Date: Wed, 1 Jul 2026 15:48:56 +0200 Subject: [PATCH] fix: Pass metadata location to StaticTable FileIO for scheme inference --- pyiceberg/table/__init__.py | 2 +- tests/table/test_init.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index 63b87d290e..77c6d555d0 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -1820,7 +1820,7 @@ def from_metadata(cls, metadata_location: str, properties: Properties = EMPTY_DI identifier=("static-table", metadata_location), metadata_location=metadata_location, metadata=metadata, - io=load_file_io({**properties, **metadata.properties}), + io=load_file_io({**properties, **metadata.properties}, location=metadata_location), catalog=NoopCatalog("static-table"), ) diff --git a/tests/table/test_init.py b/tests/table/test_init.py index 1670e62587..3f1e97768c 100644 --- a/tests/table/test_init.py +++ b/tests/table/test_init.py @@ -33,7 +33,7 @@ In, ) from pyiceberg.expressions.visitors import bind -from pyiceberg.io import PY_IO_IMPL, load_file_io +from pyiceberg.io import PY_IO_IMPL, FileIO, load_file_io from pyiceberg.partitioning import PartitionField, PartitionSpec from pyiceberg.schema import Schema from pyiceberg.table import ( @@ -1989,3 +1989,24 @@ def test_build_large_partition_predicate(table_v2: Table) -> None: ) bind(table_v2.metadata.schema(), expr, case_sensitive=True) + + +def test_static_table_forwards_location_to_table_file_io(metadata_location: str, monkeypatch: pytest.MonkeyPatch) -> None: + seen_locations: list[str | None] = [] + real_load_file_io = load_file_io + + def _spy(*args: Any, **kwargs: Any) -> FileIO: + if "location" in kwargs: + seen_locations.append(kwargs["location"]) + elif len(args) >= 2: + seen_locations.append(args[1]) + else: + seen_locations.append(None) + return real_load_file_io(*args, **kwargs) + + monkeypatch.setattr("pyiceberg.table.load_file_io", _spy) + + StaticTable.from_metadata(metadata_location) + + assert seen_locations, "expected at least one load_file_io call" + assert all(loc is not None for loc in seen_locations), f"load_file_io called without a location: {seen_locations}"