Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on superfluous parameters #3452

Merged
merged 3 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
arikfr marked this conversation as resolved.
Show resolved Hide resolved

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