summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWill Holley <willholley@gmail.com>2017-11-15 14:43:01 +0000
committerGitHub <noreply@github.com>2017-11-15 14:43:01 +0000
commitead77b26d559415e4bdd302ffae50027112567f4 (patch)
tree14b6bb5473b8df07f6d3708d1ff877213ec88f8a /src
parent16370843adbf5e9df1e6496398db4b9bac5ef8f3 (diff)
downloadcouchdb-ead77b26d559415e4bdd302ffae50027112567f4.tar.gz
Throw error on invalid use_index value (#989)
Throw an error when a user specifies a value in "use_index", of the form [<ddoc id>, <name>], that cannot be used for the current query selector. Fixes #988
Diffstat (limited to 'src')
-rw-r--r--src/mango/src/mango_cursor.erl4
-rw-r--r--src/mango/test/05-index-selection-test.py29
2 files changed, 31 insertions, 2 deletions
diff --git a/src/mango/src/mango_cursor.erl b/src/mango/src/mango_cursor.erl
index 98b2d52bd..7997d9ada 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 49946171e..fe36257e3 100644
--- a/src/mango/test/05-index-selection-test.py
+++ b/src/mango/test/05-index-selection-test.py
@@ -91,6 +91,20 @@ class IndexSelectionTests:
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 @@ class IndexSelectionTests:
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):