You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jo...@apache.org on 2019/07/29 16:19:32 UTC

[incubator-superset] branch master updated: [revert] Partial revert of #7888 (#7933)

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 af462fe  [revert] Partial revert of #7888 (#7933)
af462fe is described below

commit af462fe79f4b90a096766f8643eaa46034c2ce27
Author: John Bodley <45...@users.noreply.github.com>
AuthorDate: Mon Jul 29 09:19:21 2019 -0700

    [revert] Partial revert of #7888 (#7933)
---
 superset/connectors/sqla/models.py | 75 ++++++++++++++++++--------------------
 tests/model_tests.py               | 20 ----------
 2 files changed, 36 insertions(+), 59 deletions(-)

diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 35b8590..d528eb0 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -734,46 +734,43 @@ class SqlaTable(Model, BaseDatasource):
             if not all([flt.get(s) for s in ["col", "op"]]):
                 continue
             col = flt["col"]
-
-            if col not in cols:
-                raise Exception(_("Column '%(column)s' does not exist", column=col))
-
             op = flt["op"]
-            col_obj = cols[col]
-            is_list_target = op in ("in", "not in")
-            eq = self.filter_values_handler(
-                flt.get("val"),
-                target_column_is_numeric=col_obj.is_num,
-                is_list_target=is_list_target,
-            )
-            if op in ("in", "not in"):
-                cond = col_obj.get_sqla_col().in_(eq)
-                if "<NULL>" in eq:
-                    cond = or_(cond, col_obj.get_sqla_col() == None)  # noqa
-                if op == "not in":
-                    cond = ~cond
-                where_clause_and.append(cond)
-            else:
-                if col_obj.is_num:
-                    eq = utils.string_to_num(flt["val"])
-                if op == "==":
-                    where_clause_and.append(col_obj.get_sqla_col() == eq)
-                elif op == "!=":
-                    where_clause_and.append(col_obj.get_sqla_col() != eq)
-                elif op == ">":
-                    where_clause_and.append(col_obj.get_sqla_col() > eq)
-                elif op == "<":
-                    where_clause_and.append(col_obj.get_sqla_col() < eq)
-                elif op == ">=":
-                    where_clause_and.append(col_obj.get_sqla_col() >= eq)
-                elif op == "<=":
-                    where_clause_and.append(col_obj.get_sqla_col() <= eq)
-                elif op == "LIKE":
-                    where_clause_and.append(col_obj.get_sqla_col().like(eq))
-                elif op == "IS NULL":
-                    where_clause_and.append(col_obj.get_sqla_col() == None)  # noqa
-                elif op == "IS NOT NULL":
-                    where_clause_and.append(col_obj.get_sqla_col() != None)  # noqa
+            col_obj = cols.get(col)
+            if col_obj:
+                is_list_target = op in ("in", "not in")
+                eq = self.filter_values_handler(
+                    flt.get("val"),
+                    target_column_is_numeric=col_obj.is_num,
+                    is_list_target=is_list_target,
+                )
+                if op in ("in", "not in"):
+                    cond = col_obj.get_sqla_col().in_(eq)
+                    if "<NULL>" in eq:
+                        cond = or_(cond, col_obj.get_sqla_col() == None)  # noqa
+                    if op == "not in":
+                        cond = ~cond
+                    where_clause_and.append(cond)
+                else:
+                    if col_obj.is_num:
+                        eq = utils.string_to_num(flt["val"])
+                    if op == "==":
+                        where_clause_and.append(col_obj.get_sqla_col() == eq)
+                    elif op == "!=":
+                        where_clause_and.append(col_obj.get_sqla_col() != eq)
+                    elif op == ">":
+                        where_clause_and.append(col_obj.get_sqla_col() > eq)
+                    elif op == "<":
+                        where_clause_and.append(col_obj.get_sqla_col() < eq)
+                    elif op == ">=":
+                        where_clause_and.append(col_obj.get_sqla_col() >= eq)
+                    elif op == "<=":
+                        where_clause_and.append(col_obj.get_sqla_col() <= eq)
+                    elif op == "LIKE":
+                        where_clause_and.append(col_obj.get_sqla_col().like(eq))
+                    elif op == "IS NULL":
+                        where_clause_and.append(col_obj.get_sqla_col() == None)  # noqa
+                    elif op == "IS NOT NULL":
+                        where_clause_and.append(col_obj.get_sqla_col() != None)  # noqa
         if extras:
             where = extras.get("where")
             if where:
diff --git a/tests/model_tests.py b/tests/model_tests.py
index cd43a8c..9e6afc0 100644
--- a/tests/model_tests.py
+++ b/tests/model_tests.py
@@ -289,23 +289,3 @@ class SqlaTableModelTestCase(SupersetTestCase):
             tbl.get_query_str(query_obj)
 
         self.assertTrue("Metric 'invalid' does not exist", context.exception)
-
-    def test_query_with_non_existent_filter_columns(self):
-        tbl = self.get_table_by_name("birth_names")
-
-        query_obj = dict(
-            groupby=[],
-            metrics=["count"],
-            filter=[{"col": "invalid", "op": "==", "val": "male"}],
-            is_timeseries=False,
-            columns=["name"],
-            granularity=None,
-            from_dttm=None,
-            to_dttm=None,
-            extras={},
-        )
-
-        with self.assertRaises(Exception) as context:
-            tbl.get_query_str(query_obj)
-
-        self.assertTrue("Column 'invalid' does not exist", context.exception)