Skip to content

Commit

Permalink
fix: handle TIME column serialization (#16869)
Browse files Browse the repository at this point in the history
* Add support for datetime.time in json_int_dttm_ser

* Test base_json_conv support for datetime.time

* Group types by conversion function for JSON dump
  • Loading branch information
frafra authored and AAfghahi committed Jan 10, 2022
1 parent 290c87a commit 2171695
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 2 additions & 4 deletions superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def base_json_conv(obj: Any,) -> Any: # pylint: disable=inconsistent-return-sta
return list(obj)
if isinstance(obj, decimal.Decimal):
return float(obj)
if isinstance(obj, uuid.UUID):
if isinstance(obj, (uuid.UUID, time, LazyString)):
return str(obj)
if isinstance(obj, timedelta):
return format_timedelta(obj)
Expand All @@ -572,8 +572,6 @@ def base_json_conv(obj: Any,) -> Any: # pylint: disable=inconsistent-return-sta
return obj.decode("utf-8")
except Exception: # pylint: disable=broad-except
return "[bytes]"
if isinstance(obj, LazyString):
return str(obj)


def json_iso_dttm_ser(obj: Any, pessimistic: bool = False) -> str:
Expand All @@ -587,7 +585,7 @@ def json_iso_dttm_ser(obj: Any, pessimistic: bool = False) -> str:
val = base_json_conv(obj)
if val is not None:
return val
if isinstance(obj, (datetime, date, time, pd.Timestamp)):
if isinstance(obj, (datetime, date, pd.Timestamp)):
obj = obj.isoformat()
else:
if pessimistic:
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_base_json_conv(self):
assert isinstance(base_json_conv(set([1])), list) is True
assert isinstance(base_json_conv(Decimal("1.0")), float) is True
assert isinstance(base_json_conv(uuid.uuid4()), str) is True
assert isinstance(base_json_conv(time()), str) is True
assert isinstance(base_json_conv(timedelta(0)), str) is True

def test_zlib_compression(self):
Expand Down

0 comments on commit 2171695

Please sign in to comment.