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 d1ef81f  [ad-hoc filters] Fixing legacy conversion (#5589)
d1ef81f is described below

commit d1ef81f1027e1712a222b95088a88af21b941e53
Author: John Bodley <4567245+john-bod...@users.noreply.github.com>
AuthorDate: Fri Aug 10 10:22:06 2018 -0700

    [ad-hoc filters] Fixing legacy conversion (#5589)
---
 superset/utils.py    |  2 +-
 tests/utils_tests.py | 37 ++++++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/superset/utils.py b/superset/utils.py
index d40e657..81fb4a1 100644
--- a/superset/utils.py
+++ b/superset/utils.py
@@ -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():
diff --git a/tests/utils_tests.py b/tests/utils_tests.py
index e7b70f6..eb164b8 100644
--- a/tests/utils_tests.py
+++ b/tests/utils_tests.py
@@ -702,14 +702,45 @@ class UtilsTestCase(unittest.TestCase):
         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)

Reply via email to