Skip to content

Commit

Permalink
Fix Ability to save with Multiple Dropdown Parameters (getredash#3717)
Browse files Browse the repository at this point in the history
* support multiple associations of the same query-based dropdown parameter

* include several query-based parameters in association tests
  • Loading branch information
Omer Lachish authored and harveyrendell committed Nov 14, 2019
1 parent b8b4103 commit d7fa026
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions redash/handlers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ def get(self):

def require_access_to_dropdown_queries(user, query_def):
parameters = query_def.get('options', {}).get('parameters', [])
dropdown_query_ids = [str(p['queryId']) for p in parameters if p['type'] == 'query']
dropdown_query_ids = set([str(p['queryId']) for p in parameters if p['type'] == 'query'])

if dropdown_query_ids:
groups = models.Query.all_groups_for_query_ids(dropdown_query_ids)

if len(groups) < len(dropdown_query_ids):
abort(400, message="You are trying to associate a dropdown query that does not have a matching group."
abort(400, message="You are trying to associate a dropdown query that does not have a matching group. "
"Please verify the dropdown query id you are trying to associate with this query.")

require_access(dict(groups), user, view_only)
Expand Down
10 changes: 10 additions & 0 deletions tests/handlers/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def test_allows_association_with_authorized_dropdown_queries(self):

options = {
'parameters': [{
'name': 'foo',
'type': 'query',
'queryId': other_query.id
}, {
'name': 'bar',
'type': 'query',
'queryId': other_query.id
}]
Expand Down Expand Up @@ -251,6 +256,11 @@ def test_allows_association_with_authorized_dropdown_queries(self):
'data_source_id': self.factory.data_source.id,
'options': {
'parameters': [{
'name': 'foo',
'type': 'query',
'queryId': other_query.id
}, {
'name': 'bar',
'type': 'query',
'queryId': other_query.id
}]
Expand Down

0 comments on commit d7fa026

Please sign in to comment.