From ccd95ef97be1c6bbd332d0d0943279db12b73b0c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 25 Dec 2019 15:26:39 +0800 Subject: [PATCH] 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 --- src/pybind/mgr/restful/module.py | 38 ++++++++++++++------------------ 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/pybind/mgr/restful/module.py b/src/pybind/mgr/restful/module.py index 0f8257b7bed39..1cf3dc7a75d34 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(), -- 2.39.5