Skip to content

Commit

Permalink
Fixing filtering issues (#2223)
Browse files Browse the repository at this point in the history
* Fixing filtering issues

* Fixing off by one error
  • Loading branch information
mistercrunch authored Feb 22, 2017
1 parent aff524d commit 459f716
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion superset/assets/javascripts/explorev2/stores/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
15 changes: 5 additions & 10 deletions superset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 459f716

Please sign in to comment.