Skip to content

Commit

Permalink
[cache] Fixing cache key w/ merged extra filters (apache#3809)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored and mistercrunch committed Nov 15, 2017
1 parent 99c01e3 commit 558b946
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions superset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ def get_celery_app(config):
def merge_extra_filters(form_data):
# extra_filters are temporary/contextual filters that are external
# to the slice definition. We use those for dynamic interactive
# filters like the ones emitted by the 'Filter Box' visualization
if form_data.get('extra_filters'):
# filters like the ones emitted by the "Filter Box" visualization
if 'extra_filters' in form_data:
# __form and __to are special extra_filters that target time
# boundaries. The rest of extra_filters are simple
# [column_name in list_of_values]. `__` prefix is there to avoid
Expand Down
4 changes: 3 additions & 1 deletion superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ def get_json(self, force=False):

@property
def cache_key(self):
s = str([(k, self.form_data[k]) for k in sorted(self.form_data.keys())])
form_data = self.form_data.copy()
merge_extra_filters(form_data)
s = str([(k, form_data[k]) for k in sorted(form_data.keys())])
return hashlib.md5(s.encode('utf-8')).hexdigest()

def get_annotations(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def test_merge_extra_filters(self):
expected = {'A': 1, 'B': 2, 'c': 'test'}
merge_extra_filters(form_data)
self.assertEquals(form_data, expected)
# does nothing if empty extra_filters
# empty extra_filters
form_data = {'A': 1, 'B': 2, 'c': 'test', 'extra_filters': []}
expected = {'A': 1, 'B': 2, 'c': 'test', 'extra_filters': []}
expected = {'A': 1, 'B': 2, 'c': 'test', 'filters': []}
merge_extra_filters(form_data)
self.assertEquals(form_data, expected)
# copy over extra filters into empty filters
Expand Down

0 comments on commit 558b946

Please sign in to comment.