This is an automated email from the ASF dual-hosted git repository.
willholley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/master by this push:
new ead77b2 Throw error on invalid use_index value (#989)
ead77b2 is described below
commit ead77b26d559415e4bdd302ffae50027112567f4
Author: Will Holley <[email protected]>
AuthorDate: Wed Nov 15 14:43:01 2017 +0000
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
---
src/mango/src/mango_cursor.erl | 4 ++--
src/mango/test/05-index-selection-test.py | 29 +++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/mango/src/mango_cursor.erl b/src/mango/src/mango_cursor.erl
index 98b2d52..7997d9a 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 4994617..fe36257 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):
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].