willholley closed pull request #989: Throw friendly error on invalid use_index 
value
URL: https://github.com/apache/couchdb/pull/989
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/mango/src/mango_cursor.erl b/src/mango/src/mango_cursor.erl
index 98b2d52bdf..7997d9ada3 100644
--- a/src/mango/src/mango_cursor.erl
+++ b/src/mango/src/mango_cursor.erl
@@ -50,11 +50,11 @@ create(Db, Selector0, Opts) ->
 
     {use_index, IndexSpecified} = proplists:lookup(use_index, Opts),
     case {length(UsableIndexes), length(IndexSpecified)} of
-        {0, 1} ->
-            ?MANGO_ERROR({no_usable_index, selector_unsupported});
         {0, 0} ->
             AllDocs = mango_idx:special(Db),
             create_cursor(Db, AllDocs, Selector, Opts);
+        {0, _} ->
+            ?MANGO_ERROR({no_usable_index, selector_unsupported});
         _ ->
             create_cursor(Db, UsableIndexes, Selector, Opts)
     end.
diff --git a/src/mango/test/05-index-selection-test.py 
b/src/mango/test/05-index-selection-test.py
index 49946171e4..fe36257e38 100644
--- a/src/mango/test/05-index-selection-test.py
+++ b/src/mango/test/05-index-selection-test.py
@@ -91,6 +91,20 @@ def test_reject_use_index_invalid_fields(self):
         else:
             raise AssertionError("did not reject bad use_index")
 
+    def test_reject_use_index_ddoc_and_name_invalid_fields(self):
+        # index on ["company","manager"] which should not be valid
+        ddocid = "_design/a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
+        name = "a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
+        selector = {
+            "company": "Pharmex"
+        }
+        try:
+            self.db.find(selector, use_index=[ddocid,name])
+        except Exception as e:
+            self.assertEqual(e.response.status_code, 400)
+        else:
+            raise AssertionError("did not reject bad use_index")
+
     def test_reject_use_index_sort_order(self):
         # index on ["company","manager"] which should not be valid
         ddocid = "_design/a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
@@ -105,6 +119,21 @@ def test_reject_use_index_sort_order(self):
         else:
             raise AssertionError("did not reject bad use_index")
 
+    def test_reject_use_index_ddoc_and_name_sort_order(self):
+        # index on ["company","manager"] which should not be valid
+        ddocid = "_design/a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
+        name = "a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
+        selector = {
+            "company": {"$gt": None},
+            "manager": {"$gt": None}
+        }
+        try:
+            self.db.find(selector, use_index=[ddocid,name], 
sort=[{"manager":"desc"}])
+        except Exception as e:
+            self.assertEqual(e.response.status_code, 400)
+        else:
+            raise AssertionError("did not reject bad use_index")
+
     # This doc will not be saved given the new ddoc validation code
     # in couch_mrview
     def test_manual_bad_view_idx01(self):


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to