diff --git a/superset/viz.py b/superset/viz.py index 2496a5cb6..154841cb5 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -390,14 +390,15 @@ class BaseViz: "5 days ago" or "now"). The `extra` arguments are currently used by time shift queries, since - different time shifts wil differ only in the `from_dttm` and `to_dttm` - values which are stripped. + different time shifts wil differ only in the `from_dttm`, `to_dttm`, + `inner_from_dttm`, and `inner_to_dttm` values which are stripped. """ cache_dict = copy.copy(query_obj) cache_dict.update(extra) - for k in ["from_dttm", "to_dttm"]: - del cache_dict[k] + for k in ["from_dttm", "to_dttm", "inner_from_dttm", "inner_to_dttm"]: + if k in cache_dict: + del cache_dict[k] cache_dict["time_range"] = self.form_data.get("time_range") cache_dict["datasource"] = self.datasource.uid diff --git a/tests/core_tests.py b/tests/core_tests.py index 4e43d49d0..641a63938 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -122,7 +122,21 @@ class CoreTests(SupersetTestCase): cache_key = viz.cache_key(qobj) qobj["groupby"] = [] - self.assertNotEqual(cache_key, viz.cache_key(qobj)) + cache_key_with_groupby = viz.cache_key(qobj) + self.assertNotEqual(cache_key, cache_key_with_groupby) + + self.assertNotEqual( + viz.cache_key(qobj), viz.cache_key(qobj, time_compare="12 weeks") + ) + + self.assertNotEqual( + viz.cache_key(qobj, time_compare="28 days"), + viz.cache_key(qobj, time_compare="12 weeks"), + ) + + qobj["inner_from_dttm"] = datetime.datetime(1901, 1, 1) + + self.assertEquals(cache_key_with_groupby, viz.cache_key(qobj)) def test_get_superset_tables_not_allowed(self): example_db = utils.get_example_database()