Skip to content

Commit

Permalink
Parse filter values for possible integers and floats (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu authored and Alanna Scott committed Feb 25, 2017
1 parent 4d900c9 commit ec1f022
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions superset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ def visit_column(element, compiler, **kw):
col_obj = cols[col]
if op in ('in', 'not in'):
values = [types.strip("'").strip('"') for types in eq]
values = [utils.js_string_to_num(s) for s in values]
cond = col_obj.sqla_col.in_(values)
if op == 'not in':
cond = ~cond
Expand Down Expand Up @@ -2574,6 +2575,7 @@ def get_filters(raw_filters):
fields = []
# Distinguish quoted values with regular value types
values = [types.replace("'", '') for types in eq]
values = [utils.js_string_to_num(s) for s in values]
if len(values) > 1:
for s in values:
s = s.strip()
Expand Down
8 changes: 8 additions & 0 deletions superset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ def __get__(self, obj, objtype):
def js_string_to_python(item):
return None if item in ('null', 'undefined') else item

def js_string_to_num(item):
if item.isdigit():
return int(item)
s = item
try:
s = float(item)
except ValueError:
return s

class DimSelector(Having):
def __init__(self, **args):
Expand Down

0 comments on commit ec1f022

Please sign in to comment.