From: Adam King Date: Wed, 17 Apr 2024 17:34:45 +0000 (-0400) Subject: mgr/pybind/object_format: fix json-pretty being marked invalid X-Git-Tag: v20.0.0~1976^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cd988a01a0edf13882527f5526f1793d4dece437;p=ceph.git mgr/pybind/object_format: fix json-pretty being marked invalid without this patch you'd get ``` [ceph: root@vm-00 /]# ceph nfs cluster info --format json-pretty Error EINVAL: Unknown format name: json-pretty ``` this seems to be because valid formats are checked using the class ``` class Format(str, enum.Enum): plain = "plain" json = "json" json_pretty = "json-pretty" yaml = "yaml" xml_pretty = "xml-pretty" xml = "xml" ``` and then ``` set(str(v) for v in Format.__members__) ``` but that resolves to ``` {'yaml', 'json_pretty', 'plain', 'xml', 'json', 'xml_pretty'} ``` and so json-pretty is marked as invalid. Note that it's also impossible to pass json_pretty as the format as core ceph blocks it with invalid choice: 'json_pretty' (choose from 'json', 'json-pretty', 'xml', 'xml-pretty', 'plain', 'yaml') Fixes: https://tracker.ceph.com/issues/65554 Signed-off-by: Adam King --- diff --git a/src/pybind/mgr/object_format.py b/src/pybind/mgr/object_format.py index 4a2b6fa8b69b..85b19711044c 100644 --- a/src/pybind/mgr/object_format.py +++ b/src/pybind/mgr/object_format.py @@ -533,9 +533,9 @@ class Responder: formatter = self._formatter(obj) if format_req is None: format_req = self.default_format - if format_req not in formatter.valid_formats(): - raise UnknownFormat(format_req) req = str(format_req).replace("-", "_") + if req not in formatter.valid_formats(): + raise UnknownFormat(format_req) ffunc = getattr(formatter, f"format_{req}", None) if ffunc is None: raise UnsupportedFormat(format_req)