mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
Handle memoryview like bytes instances and decode bytes to utf8 (#7062)
This commit is contained in:
committed by
Maxime Beauchemin
parent
aa9e273900
commit
c1c8e50360
@@ -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]'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user