From c1c8e503601831aa5eb5125bb521ecdd141a3425 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt <33317356+villebro@users.noreply.github.com> Date: Wed, 20 Mar 2019 02:57:09 +0200 Subject: [PATCH] Handle memoryview like bytes instances and decode bytes to utf8 (#7062) --- superset/utils/core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/superset/utils/core.py b/superset/utils/core.py index 022e9c558..3b47298b3 100644 --- a/superset/utils/core.py +++ b/superset/utils/core.py @@ -328,6 +328,8 @@ def datetime_f(dttm): def base_json_conv(obj): + if isinstance(obj, memoryview): + obj = obj.tobytes() if isinstance(obj, numpy.int64): return int(obj) elif isinstance(obj, numpy.bool_): @@ -340,11 +342,9 @@ def base_json_conv(obj): return str(obj) elif isinstance(obj, timedelta): return str(obj) - elif isinstance(obj, memoryview): - return str(obj.tobytes(), 'utf8') elif isinstance(obj, bytes): try: - return '{}'.format(obj) + return obj.decode('utf-8') except Exception: return '[bytes]'