From 459f7160ac7587f92c8213b496fb64518329c1be Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 22 Feb 2017 15:17:20 -0800 Subject: [PATCH] Fixing filtering issues (#2223) * Fixing filtering issues * Fixing off by one error --- .../assets/javascripts/explorev2/stores/store.js | 2 +- superset/models.py | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/superset/assets/javascripts/explorev2/stores/store.js b/superset/assets/javascripts/explorev2/stores/store.js index 8852e8ea41e5d..28c50b73a5aed 100644 --- a/superset/assets/javascripts/explorev2/stores/store.js +++ b/superset/assets/javascripts/explorev2/stores/store.js @@ -56,7 +56,7 @@ export function getControlsState(state, form_data) { // Removing invalid filters that point to a now inexisting column if (control.type === 'FilterControl' && control.choices) { const choiceValues = control.choices.map(c => c[0]); - formData[k] = control.value.filter(flt => choiceValues.indexOf(flt.col) > 0); + formData[k] = formData[k].filter(flt => choiceValues.indexOf(flt.col) >= 0); } if (typeof control.default === 'function') { diff --git a/superset/models.py b/superset/models.py index cb6cd6cda65ab..553309ad83b38 100644 --- a/superset/models.py +++ b/superset/models.py @@ -87,9 +87,6 @@ def __init__( # noqa self.error_message = error_message -FilterPattern = re.compile(r'''((?:[^,"']|"[^"]*"|'[^']*')+)''') - - def set_perm(mapper, connection, target): # noqa if target.perm != target.get_perm(): link_table = target.__table__ @@ -1390,11 +1387,10 @@ def visit_column(element, compiler, **kw): continue col = flt['col'] op = flt['op'] - eq = ','.join(flt['val']) + eq = flt['val'] col_obj = cols[col] if op in ('in', 'not in'): - splitted = FilterPattern.split(eq)[1::2] - values = [types.strip("'").strip('"') for types in splitted] + values = [types.strip("'").strip('"') for types in eq] cond = col_obj.sqla_col.in_(values) if op == 'not in': cond = ~cond @@ -2554,15 +2550,14 @@ def get_filters(raw_filters): elif op in ('in', 'not in'): fields = [] # Distinguish quoted values with regular value types - split = FilterPattern.split(eq)[1::2] - values = [types.replace("'", '') for types in split] + values = [types.replace("'", '') for types in eq] if len(values) > 1: for s in values: s = s.strip() fields.append(Dimension(col) == s) cond = Filter(type="or", fields=fields) - else: - cond = Dimension(col) == eq + elif len(values) == 1: + cond = Dimension(col) == eq[0] if op == 'not in': cond = ~cond elif op == 'regex':