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

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


The following commit(s) were added to refs/heads/main by this push:
     new 4ba3ba484 fix(cli): emit one JSON object per ref in list-refs (#4169)
4ba3ba484 is described below

commit 4ba3ba4843ab7fdf96f9961d7695440be3e8dcf4
Author: Aayush Kumar bhat <[email protected]>
AuthorDate: Wed Oct 28 08:29:04 2026 +0000

    fix(cli): emit one JSON object per ref in list-refs (#4169)
    
    The nested comprehension emitted one object per retention property, so a 
single snapshot ref produced several JSON objects. Build one object per ref and 
merge its properties into it.
---
 pyiceberg/cli/output.py  |  8 +-------
 tests/cli/test_output.py | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/pyiceberg/cli/output.py b/pyiceberg/cli/output.py
index cb8e247bf..cfb00abb7 100644
--- a/pyiceberg/cli/output.py
+++ b/pyiceberg/cli/output.py
@@ -272,10 +272,4 @@ class JsonOutput(Output):
         self._out({"version": version})
 
     def describe_refs(self, refs: list[tuple[str, SnapshotRefType, dict[str, 
str]]]) -> None:
-        self._out(
-            [
-                {"name": name, "type": type, detail_key: detail_val}
-                for name, type, detail in refs
-                for detail_key, detail_val in detail.items()
-            ]
-        )
+        self._out([{"name": name, "type": ref_type, **detail} for name, 
ref_type, detail in refs])
diff --git a/tests/cli/test_output.py b/tests/cli/test_output.py
index a67d5ea25..7b27a02c5 100644
--- a/tests/cli/test_output.py
+++ b/tests/cli/test_output.py
@@ -14,3 +14,35 @@
 #  KIND, either express or implied.  See the License for the
 #  specific language governing permissions and limitations
 #  under the License.
+import json
+
+import pytest
+
+from pyiceberg.cli.output import JsonOutput
+from pyiceberg.table.refs import SnapshotRefType
+
+
+def test_json_describe_refs_emits_one_object_per_ref(capsys: 
pytest.CaptureFixture[str]) -> None:
+    JsonOutput().describe_refs(
+        [
+            (
+                "main",
+                SnapshotRefType.BRANCH,
+                {
+                    "min_snapshots_to_keep": "1",
+                    "max_snapshot_age_ms": "432000000",
+                    "max_ref_age_ms": "forever",
+                },
+            )
+        ]
+    )
+
+    assert json.loads(capsys.readouterr().out) == [
+        {
+            "name": "main",
+            "type": "branch",
+            "min_snapshots_to_keep": "1",
+            "max_snapshot_age_ms": "432000000",
+            "max_ref_age_ms": "forever",
+        }
+    ]

Reply via email to