You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/08/10 17:22:08 UTC

[GitHub] john-bodley closed pull request #5589: [ad-hoc filters] Fixing legacy conversion

john-bodley closed pull request #5589: [ad-hoc filters] Fixing legacy conversion
URL: https://github.com/apache/incubator-superset/pull/5589
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/utils.py b/superset/utils.py
index d40e657dc7..81fb4a1815 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 e7b70f6eed..eb164b8b1a 100644
--- a/tests/utils_tests.py
+++ b/tests/utils_tests.py
@@ -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)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org