Skip to content

Commit

Permalink
when working with a schema, fail in the case that there are parameters (
Browse files Browse the repository at this point in the history
#3452)

which are not part of the schema
  • Loading branch information
Omer Lachish authored and arikfr committed Feb 19, 2019
1 parent f421119 commit 0bca2d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion redash/utils/parameterized_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ def apply(self, parameters):
return self

def _valid(self, name, value):
if not self.schema:
return True

definition = next((definition for definition in self.schema if definition["name"] == name), None)

if not definition:
return True
return False

validators = {
"text": lambda value: isinstance(value, basestring),
Expand Down
7 changes: 7 additions & 0 deletions tests/utils/test_parameterized_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def test_handles_objects(self):
})
self.assertEqual(set([]), query.missing_params)

def test_raises_on_parameters_not_in_schema(self):
schema = [{"name": "bar", "type": "text"}]
query = ParameterizedQuery("foo", schema)

with pytest.raises(InvalidParameterError):
query.apply({"qux": 7})

def test_raises_on_invalid_text_parameters(self):
schema = [{"name": "bar", "type": "text"}]
query = ParameterizedQuery("foo", schema)
Expand Down

0 comments on commit 0bca2d8

Please sign in to comment.