You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2021/11/11 08:36:29 UTC

[superset] branch master updated: fix: handle TIME column serialization (#16869)

This is an automated email from the ASF dual-hosted git repository.

villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d77f36  fix: handle TIME column serialization (#16869)
0d77f36 is described below

commit 0d77f36679a5714ea7402085988d4fb9867dd913
Author: Francesco Frassinelli <fr...@gmail.com>
AuthorDate: Thu Nov 11 09:35:00 2021 +0100

    fix: handle TIME column serialization (#16869)
    
    * 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
---
 superset/utils/core.py                 | 6 ++----
 tests/integration_tests/utils_tests.py | 1 +
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/superset/utils/core.py b/superset/utils/core.py
index fad19f4..4013a65 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -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)
@@ -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:
@@ -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:
diff --git a/tests/integration_tests/utils_tests.py b/tests/integration_tests/utils_tests.py
index 1f01d43..5ac41be 100644
--- a/tests/integration_tests/utils_tests.py
+++ b/tests/integration_tests/utils_tests.py
@@ -117,6 +117,7 @@ class TestUtils(SupersetTestCase):
         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):