diff options
author | Will Holley <willholley@gmail.com> | 2017-09-11 17:13:00 +0100 |
---|---|---|
committer | Will Holley <willholley@gmail.com> | 2017-09-12 13:53:02 +0100 |
commit | 302126b75b124f4f00a8c9629b086c8b92d42784 (patch) | |
tree | 921b3f661fcea53bef4f97a5afd5e76919df2212 | |
parent | 41e2984166d65677634c36bb204195c770a5cb03 (diff) | |
download | couchdb-302126b75b124f4f00a8c9629b086c8b92d42784.tar.gz |
Return 400 when no index can fulfil a sort
Fixes a regression where a 500 status code was returned when
no index is available to service a _find query because the
sort order does not match any available indexes.
-rw-r--r-- | src/mango/src/mango_error.erl | 6 | ||||
-rw-r--r-- | src/mango/test/05-index-selection-test.py | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/mango/src/mango_error.erl b/src/mango/src/mango_error.erl index 361016524..4f8ae204d 100644 --- a/src/mango/src/mango_error.erl +++ b/src/mango/src/mango_error.erl @@ -21,19 +21,19 @@ ]). -info(mango_cursor, {no_usable_index, no_indexes_defined}) -> +info(mango_idx, {no_usable_index, no_indexes_defined}) -> { 400, <<"no_usable_index">>, <<"There are no indexes defined in this database.">> }; -info(mango_cursor, {no_usable_index, no_index_matching_name}) -> +info(mango_idx, {no_usable_index, no_index_matching_name}) -> { 400, <<"no_usable_index">>, <<"No index matches the index specified with \"use_index\"">> }; -info(mango_cursor, {no_usable_index, missing_sort_index}) -> +info(mango_idx, {no_usable_index, missing_sort_index}) -> { 400, <<"no_usable_index">>, diff --git a/src/mango/test/05-index-selection-test.py b/src/mango/test/05-index-selection-test.py index a78c12f77..2fb0a405b 100644 --- a/src/mango/test/05-index-selection-test.py +++ b/src/mango/test/05-index-selection-test.py @@ -74,6 +74,14 @@ class IndexSelectionTests(mango.UserDocsTests): }, use_index=ddocid, explain=True) self.assertEqual(resp["index"]["ddoc"], ddocid) + def test_no_valid_sort_index(self): + try: + self.db.find({"_id": {"$gt": None}}, sort=["name"], return_raw=True) + except Exception, e: + self.assertEqual(e.response.status_code, 400) + else: + raise AssertionError("bad find") + def test_invalid_use_index(self): # ddoc id for the age index ddocid = "_design/ad3d537c03cd7c6a43cf8dff66ef70ea54c2b40f" |