Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle TIME column serialization #16869

Merged
merged 4 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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