Skip to content

Commit 4ba3ba4

Browse files
authored
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.
1 parent 27a5162 commit 4ba3ba4

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

‎pyiceberg/cli/output.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,4 @@ def version(self, version: str) -> None:
272272
self._out({"version": version})
273273

274274
def describe_refs(self, refs: list[tuple[str, SnapshotRefType, dict[str, str]]]) -> None:
275-
self._out(
276-
[
277-
{"name": name, "type": type, detail_key: detail_val}
278-
for name, type, detail in refs
279-
for detail_key, detail_val in detail.items()
280-
]
281-
)
275+
self._out([{"name": name, "type": ref_type, **detail} for name, ref_type, detail in refs])

‎tests/cli/test_output.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,35 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
import json
18+
19+
import pytest
20+
21+
from pyiceberg.cli.output import JsonOutput
22+
from pyiceberg.table.refs import SnapshotRefType
23+
24+
25+
def test_json_describe_refs_emits_one_object_per_ref(capsys: pytest.CaptureFixture[str]) -> None:
26+
JsonOutput().describe_refs(
27+
[
28+
(
29+
"main",
30+
SnapshotRefType.BRANCH,
31+
{
32+
"min_snapshots_to_keep": "1",
33+
"max_snapshot_age_ms": "432000000",
34+
"max_ref_age_ms": "forever",
35+
},
36+
)
37+
]
38+
)
39+
40+
assert json.loads(capsys.readouterr().out) == [
41+
{
42+
"name": "main",
43+
"type": "branch",
44+
"min_snapshots_to_keep": "1",
45+
"max_snapshot_age_ms": "432000000",
46+
"max_ref_age_ms": "forever",
47+
}
48+
]

0 commit comments

Comments
 (0)