From c6812274e4a5ebf47f07c9ebcdc5fb4e3f16d7fd Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 11 Feb 2020 09:04:49 -0500 Subject: [PATCH] Fix media list through collective The Media class was not serializable by msgpack. Fix this and improve error messages in future instances of this behavior. --- confluent_server/confluent/core.py | 4 ++-- confluent_server/confluent/exceptions.py | 6 ++++-- confluent_server/confluent/messages.py | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/confluent_server/confluent/core.py b/confluent_server/confluent/core.py index ee62c5e8..997781cd 100644 --- a/confluent_server/confluent/core.py +++ b/confluent_server/confluent/core.py @@ -753,9 +753,9 @@ def _forward_rsp(connection, res): r = msgpack.packb( ['Exception', 'Unable to serialize response ' + repr(res)], use_bin_type=False) - except Exception: + except Exception as e: r = msgpack.packb( - ['Exception', 'Unable to serialize response ' + repr(res)], + ['Exception', 'Unable to serialize response ' + repr(res) + ' due to ' + str(e)], use_bin_type=False) rlen = len(r) if not rlen: diff --git a/confluent_server/confluent/exceptions.py b/confluent_server/confluent/exceptions.py index bce75763..cb856094 100644 --- a/confluent_server/confluent/exceptions.py +++ b/confluent_server/confluent/exceptions.py @@ -21,10 +21,12 @@ import msgpack def deserialize_exc(msg): excd = msgpack.unpackb(msg, raw=False) + if excd[0] == 'Exception': + return Exception(excd[1]) if excd[0] not in globals(): - return False + return Exception('Cannot deserialize: {0}'.format(repr(excd))) if not issubclass(excd[0], ConfluentException): - return False + return Exception('Cannot deserialize: {0}'.format(repr(excd))) return globals(excd[0])(*excd[1]) class ConfluentException(Exception): diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 3fc63b8e..b14d12ee 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -578,9 +578,11 @@ class DetachMedia(ConfluentMessage): class Media(ConfluentMessage): - def __init__(self, node, media): - self.myargs = (node, media) - self.kvpairs = {node: {'name': media.name, 'url': media.url}} + def __init__(self, node, media=None, rawmedia=None): + if media: + rawmedia = {'name': media.name, 'url': media.url} + self.myargs = (node, None, rawmedia) + self.kvpairs = {node: rawmedia} class SavedFile(ConfluentMessage): def __init__(self, node, file):