Repository: getredash/redash

Issue:
Can't save queries with more than one Dropdown Parameter from the same query
<!--

We use GitHub only for bug reports 🐛

Anything else should be posted to https://discuss.redash.io 👫

🚨For support, help & questions use https://discuss.redash.io/c/support
💡For feature requests & ideas use https://discuss.redash.io/c/feature-requests

**Found a security vulnerability?** Please email security@redash.io to report any security vulnerabilities. We will acknowledge receipt of your vulnerability and strive to send you regular updates about our progress. If you're curious about the status of your disclosure please feel free to email us again. If you want to encrypt your disclosure email, you can use this PGP key.

-->

### Issue Summary

It's not possible to save a query that contains more than one Query Based Dropdown Parameter from the same query.

### Steps to Reproduce

1. Create a Query and add a Query Based Dropdown Parameter (you can use [this query](https://redash-preview.netlify.com/queries/123) to test - use query "v7 Authors" for the new parameter) and save it
2. Add another Query Based Dropdown Parameter using the same query as the first one
3. Try to save the query

It should save the query successfully.

![issue-dropdown-parameters-1](https://user-images.githubusercontent.com/3356951/56169940-35a1e600-5fb6-11e9-81ce-6fd1eb0b219b.gif)


### Technical details:

* Redash Version: Latest
* Browser/OS: Any
* How did you install Redash: --



Discussion:

Resolving patch:
diff --git a/redash/handlers/queries.py b/redash/handlers/queries.py
--- a/redash/handlers/queries.py
+++ b/redash/handlers/queries.py
@@ -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)


Test patch:
diff --git a/tests/handlers/test_queries.py b/tests/handlers/test_queries.py
--- a/tests/handlers/test_queries.py
+++ b/tests/handlers/test_queries.py
@@ -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
             }]
@@ -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
                 }]