From: Kefu Chai Date: Wed, 25 Dec 2019 07:26:39 +0000 (+0800) Subject: mgr/restful: jsonify lists instead of maps X-Git-Tag: v15.1.0~362^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F32421%2Fhead;p=ceph.git mgr/restful: jsonify lists instead of maps in python3, `map()` returns a `map` instance which is iterable, while in python2, `map()` returns a `list`, but `JSONEncoder.default()` expects a list or whatever which inherits from `json.JSONEncoder`. in this change, we just return a materized list instead of a map for json encoder. Fixes: https://tracker.ceph.com/issues/43416 Signed-off-by: Kefu Chai --- diff --git a/src/pybind/mgr/restful/module.py b/src/pybind/mgr/restful/module.py index 0f8257b7bed3..1cf3dc7a75d3 100644 --- a/src/pybind/mgr/restful/module.py +++ b/src/pybind/mgr/restful/module.py @@ -159,37 +159,31 @@ class CommandsRequest(object): def __json__(self): return { 'id': self.id, - 'running': map( - lambda x: { + 'running': [ + { 'command': x.command, 'outs': x.outs, 'outb': x.outb, - }, - self.running - ), - 'finished': map( - lambda x: { + } for x in self.running + ], + 'finished': [ + { 'command': x.command, 'outs': x.outs, 'outb': x.outb, - }, - self.finished - ), - 'waiting': map( - lambda x: map( - lambda y: common.humanify_command(y), - x - ), - self.waiting - ), - 'failed': map( - lambda x: { + } for x in self.finished + ], + 'waiting': [ + [common.humanify_command(y) for y in x] + for x in self.waiting + ], + 'failed': [ + { 'command': x.command, 'outs': x.outs, 'outb': x.outb, - }, - self.failed - ), + } for x in self.failed + ], 'is_waiting': self.is_waiting(), 'is_finished': self.is_finished(), 'has_failed': self.has_failed(),