Skip to content

Commit

Permalink
Parse filter values for possible integers and floats
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu committed Feb 24, 2017
1 parent cad392e commit b61bec8
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
Expand Up @@ -1391,6 +1391,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 @@ -2551,6 +2552,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
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 b61bec8

Please sign in to comment.