mirror of https://github.com/apache/superset.git
fix: caching on viz with relative time ranges and time compare (#10061)
This commit is contained in:
parent
51a42a27e7
commit
7504b1cf20
|
@ -390,14 +390,15 @@ class BaseViz:
|
||||||
"5 days ago" or "now").
|
"5 days ago" or "now").
|
||||||
|
|
||||||
The `extra` arguments are currently used by time shift queries, since
|
The `extra` arguments are currently used by time shift queries, since
|
||||||
different time shifts wil differ only in the `from_dttm` and `to_dttm`
|
different time shifts wil differ only in the `from_dttm`, `to_dttm`,
|
||||||
values which are stripped.
|
`inner_from_dttm`, and `inner_to_dttm` values which are stripped.
|
||||||
"""
|
"""
|
||||||
cache_dict = copy.copy(query_obj)
|
cache_dict = copy.copy(query_obj)
|
||||||
cache_dict.update(extra)
|
cache_dict.update(extra)
|
||||||
|
|
||||||
for k in ["from_dttm", "to_dttm"]:
|
for k in ["from_dttm", "to_dttm", "inner_from_dttm", "inner_to_dttm"]:
|
||||||
del cache_dict[k]
|
if k in cache_dict:
|
||||||
|
del cache_dict[k]
|
||||||
|
|
||||||
cache_dict["time_range"] = self.form_data.get("time_range")
|
cache_dict["time_range"] = self.form_data.get("time_range")
|
||||||
cache_dict["datasource"] = self.datasource.uid
|
cache_dict["datasource"] = self.datasource.uid
|
||||||
|
|
|
@ -122,7 +122,21 @@ class CoreTests(SupersetTestCase):
|
||||||
cache_key = viz.cache_key(qobj)
|
cache_key = viz.cache_key(qobj)
|
||||||
|
|
||||||
qobj["groupby"] = []
|
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):
|
def test_get_superset_tables_not_allowed(self):
|
||||||
example_db = utils.get_example_database()
|
example_db = utils.get_example_database()
|
||||||
|
|
Loading…
Reference in New Issue