You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jo...@apache.org on 2019/10/23 23:04:59 UTC

[incubator-superset] branch master updated: [fix] Updating parse_human_timedelta typing (#8436)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 786d770  [fix] Updating parse_human_timedelta typing (#8436)
786d770 is described below

commit 786d7706e7cbe1bc266db47c8b4865b4c94b1d58
Author: John Bodley <45...@users.noreply.github.com>
AuthorDate: Wed Oct 23 16:04:46 2019 -0700

    [fix] Updating parse_human_timedelta typing (#8436)
---
 superset/common/query_object.py | 4 +---
 superset/utils/core.py          | 2 +-
 tests/utils_tests.py            | 1 +
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/superset/common/query_object.py b/superset/common/query_object.py
index 4c83c87..b2822e3 100644
--- a/superset/common/query_object.py
+++ b/superset/common/query_object.py
@@ -78,9 +78,7 @@ class QueryObject:
         )
         self.is_timeseries = is_timeseries
         self.time_range = time_range
-        self.time_shift = (
-            utils.parse_human_timedelta(time_shift) if time_shift else None
-        )
+        self.time_shift = utils.parse_human_timedelta(time_shift)
         self.groupby = groupby or []
 
         # Temporal solution for backward compatability issue
diff --git a/superset/utils/core.py b/superset/utils/core.py
index f4d1ac8..a27ff71 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -291,7 +291,7 @@ class DashboardEncoder(json.JSONEncoder):
             return json.JSONEncoder(sort_keys=True).default(self, o)
 
 
-def parse_human_timedelta(s: str) -> timedelta:
+def parse_human_timedelta(s: Optional[str]) -> timedelta:
     """
     Returns ``datetime.datetime`` from natural language time deltas
 
diff --git a/tests/utils_tests.py b/tests/utils_tests.py
index ad9fa0d..02703f0 100644
--- a/tests/utils_tests.py
+++ b/tests/utils_tests.py
@@ -130,6 +130,7 @@ class UtilsTestCase(unittest.TestCase):
         self.assertEqual(parse_human_timedelta("now"), timedelta(0))
         self.assertEqual(parse_human_timedelta("1 year"), timedelta(366))
         self.assertEqual(parse_human_timedelta("-1 year"), timedelta(-365))
+        self.assertEqual(parse_human_timedelta(None), timedelta(0))
 
     @patch("superset.utils.core.datetime")
     def test_parse_past_timedelta(self, mock_datetime):