Skip to content

Commit

Permalink
[ad-hoc filters] Fixing legacy conversion (apache#5589)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Aug 10, 2018
1 parent 682ca38 commit d1ef81f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion superset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def get_since_until(form_data):
def convert_legacy_filters_into_adhoc(fd):
mapping = {'having': 'having_filters', 'where': 'filters'}

if 'adhoc_filters' not in fd:
if not fd.get('adhoc_filters'):
fd['adhoc_filters'] = []

for clause, filters in mapping.items():
Expand Down
37 changes: 34 additions & 3 deletions tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,45 @@ def test_convert_legacy_filters_into_adhoc_having_filters(self):
self.assertEquals(form_data, expected)

@patch('superset.utils.to_adhoc', mock_to_adhoc)
def test_convert_legacy_filters_into_adhoc_existing(self):
def test_convert_legacy_filters_into_adhoc_present_and_empty(self):
form_data = {
'adhoc_filters': [],
'where': 'a = 1',
}
expected = {
'adhoc_filters': [
{
'clause': 'WHERE',
'expressionType': 'SQL',
'sqlExpression': 'a = 1',
},
],
}
convert_legacy_filters_into_adhoc(form_data)
self.assertEquals(form_data, expected)

@patch('superset.utils.to_adhoc', mock_to_adhoc)
def test_convert_legacy_filters_into_adhoc_present_and_nonempty(self):
form_data = {
'adhoc_filters': [
{
'clause': 'WHERE',
'expressionType': 'SQL',
'sqlExpression': 'a = 1',
},
],
'filters': [{'col': 'a', 'op': 'in', 'val': 'someval'}],
'having': 'COUNT(1) = 1',
'having_filters': [{'col': 'COUNT(1)', 'op': '==', 'val': 1}],
'where': 'a = 1',
}
expected = {'adhoc_filters': []}
expected = {
'adhoc_filters': [
{
'clause': 'WHERE',
'expressionType': 'SQL',
'sqlExpression': 'a = 1',
},
],
}
convert_legacy_filters_into_adhoc(form_data)
self.assertEquals(form_data, expected)

0 comments on commit d1ef81f

Please sign in to comment.