json serialize additional types in protonmsg

Fixes: https://pagure.io/koji/issue/741
This commit is contained in:
Tomas Kopecek 2017-12-21 13:10:01 +01:00 committed by Mike McLean
parent f869eb4158
commit 3bfcc6a66e
2 changed files with 11 additions and 2 deletions

View file

@ -130,12 +130,20 @@ class TimeoutHandler(MessagingHandler):
self.timeout_task.cancel()
self.timeout_task = None
def json_serialize(o):
"""JSON helper to encode otherwise unserializable data types"""
if isinstance(o, set):
return list(o)
raise TypeError(repr(o) + " is not JSON serializable")
def queue_msg(address, props, data):
msgs = getattr(context, 'protonmsg_msgs', None)
if msgs is None:
msgs = []
context.protonmsg_msgs = msgs
body = json.dumps(data)
body = json.dumps(data, default=json_serialize)
msgs.append((address, props, body))
@convert_datetime