Skip to content

Commit

Permalink
Fix: accept integer values in dropdowns. (#3596)
Browse files Browse the repository at this point in the history
  • Loading branch information
arikfr authored Mar 17, 2019
1 parent 1f74c0b commit 93aa6b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redash/utils/parameterized_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _valid(self, name, value):
"text": lambda value: isinstance(value, basestring),
"number": lambda value: isinstance(value, Number),
"enum": lambda value: value in definition["enumOptions"],
"query": lambda value: value in [v["value"] for v in dropdown_values(definition["queryId"])],
"query": lambda value: unicode(value) in [v["value"] for v in dropdown_values(definition["queryId"])],
"date": _is_date,
"datetime-local": _is_date,
"datetime-with-seconds": _is_date,
Expand Down
9 changes: 9 additions & 0 deletions tests/utils/test_parameterized_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ def test_validates_enum_parameters(self):

self.assertEquals("foo baz", query.text)

@patch('redash.utils.parameterized_query.dropdown_values', return_value=[{"value": "1"}])
def test_validation_accepts_integer_values_for_dropdowns(self, _):
schema = [{"name": "bar", "type": "query", "queryId": 1}]
query = ParameterizedQuery("foo {{bar}}", schema)

query.apply({"bar": 1})

self.assertEquals("foo 1", query.text)

@patch('redash.utils.parameterized_query.dropdown_values')
def test_raises_on_invalid_query_parameters(self, _):
schema = [{"name": "bar", "type": "query", "queryId": 1}]
Expand Down

0 comments on commit 93aa6b5

Please sign in to comment.