diff --git a/pyiceberg/table/inspect.py b/pyiceberg/table/inspect.py index 4feba3d532..167240dcf8 100644 --- a/pyiceberg/table/inspect.py +++ b/pyiceberg/table/inspect.py @@ -138,7 +138,7 @@ def snapshots(self) -> pa.Table: "committed_at": datetime.fromtimestamp(snapshot.timestamp_ms / 1000.0, tz=UTC), "snapshot_id": snapshot.snapshot_id, "parent_id": snapshot.parent_snapshot_id, - "operation": str(operation), + "operation": operation, "manifest_list": snapshot.manifest_list, "summary": additional_properties, } diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index e507b62f71..7253452d11 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -104,6 +104,21 @@ def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMem assert files[0]["column_sizes"] is None +def test_inspect_snapshots_operation_is_null_without_summary(catalog: InMemoryCatalog) -> None: + schema = Schema(NestedField(1, "x", LongType(), required=False)) + tbl = catalog.create_table("default.snapshot_without_summary", schema) + tbl.append(pa.table({"x": [1]}, schema=pa.schema([pa.field("x", pa.int64())]))) + assert tbl.inspect.snapshots().column("operation").to_pylist() == ["append"] + + # The summary is optional in v1, so a snapshot without one has no operation + snapshot = tbl.metadata.snapshots[0].model_copy(update={"summary": None}) + tbl.metadata = tbl.metadata.model_copy(update={"snapshots": [snapshot]}) + + snapshots = tbl.inspect.snapshots() + assert snapshots.column("operation").to_pylist() == [None] + assert snapshots.column("summary").to_pylist() == [None] + + @pytest.mark.parametrize("newest_first", [False, True]) def test_partitions_last_updated_uses_latest_snapshot_regardless_of_order(newest_first: bool) -> None: # Manifest entries are visited in manifest order, which is not chronological, so the