You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wi...@apache.org on 2020/02/03 11:05:33 UTC

[couchdb] branch master updated: Return mango warnings as a delimited string

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 a19b9ff  Return mango warnings as a delimited string
a19b9ff is described below

commit a19b9ff23ddb7da217954f963009d38c630891a7
Author: Will Holley <wi...@gmail.com>
AuthorDate: Mon Feb 3 10:19:59 2020 +0000

    Return mango warnings as a delimited string
    
    The CouchDB API defines the warning field returned by _find to be
    a string (and this is what Fauxton expects). 5d55e289 was missing
    a string conversion and returned the warning(s) as an array. This
    restores the intended behaviour.
---
 src/mango/src/mango_cursor.erl              | 2 +-
 src/mango/test/05-index-selection-test.py   | 8 ++++----
 src/mango/test/12-use-correct-index-test.py | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/mango/src/mango_cursor.erl b/src/mango/src/mango_cursor.erl
index 29be494..b1cb414 100644
--- a/src/mango/src/mango_cursor.erl
+++ b/src/mango/src/mango_cursor.erl
@@ -133,7 +133,7 @@ maybe_add_warning(UserFun, #cursor{index = Index, opts = Opts}, Stats, UserAcc)
         [] ->
             UserAcc;
         _ ->
-            WarningStr = lists:join(<<"\n">>, Warnings),
+            WarningStr = iolist_to_binary(lists:join(<<"\n">>, Warnings)),
             Arg = {add_key, warning, WarningStr},
             {_Go, UserAcc1} = UserFun(Arg, UserAcc),
             UserAcc1
diff --git a/src/mango/test/05-index-selection-test.py b/src/mango/test/05-index-selection-test.py
index 271e361..2bc5a88 100644
--- a/src/mango/test/05-index-selection-test.py
+++ b/src/mango/test/05-index-selection-test.py
@@ -84,7 +84,7 @@ class IndexSelectionTests:
         ddocid = "_design/age"
         r = self.db.find({}, use_index=ddocid, return_raw=True)
         self.assertEqual(
-            r["warning"][0].lower(),
+            r["warning"].split('\n')[0].lower(),
             "{0} was not used because it does not contain a valid index for this query.".format(
                 ddocid
             ),
@@ -107,7 +107,7 @@ class IndexSelectionTests:
         selector = {"company": "Pharmex"}
         r = self.db.find(selector, use_index=ddocid, return_raw=True)
         self.assertEqual(
-            r["warning"][0].lower(),
+            r["warning"].split('\n')[0].lower(),
             "{0} was not used because it does not contain a valid index for this query.".format(
                 ddocid
             ),
@@ -124,7 +124,7 @@ class IndexSelectionTests:
 
         resp = self.db.find(selector, use_index=[ddocid, name], return_raw=True)
         self.assertEqual(
-            resp["warning"][0].lower(),
+            resp["warning"].split('\n')[0].lower(),
             "{0}, {1} was not used because it is not a valid index for this query.".format(
                 ddocid, name
             ),
@@ -162,7 +162,7 @@ class IndexSelectionTests:
             selector, sort=["foo", "bar"], use_index=ddocid_invalid, return_raw=True
         )
         self.assertEqual(
-            resp["warning"][0].lower(),
+            resp["warning"].split('\n')[0].lower(),
             "{0} was not used because it does not contain a valid index for this query.".format(
                 ddocid_invalid
             ),
diff --git a/src/mango/test/12-use-correct-index-test.py b/src/mango/test/12-use-correct-index-test.py
index 3a2f60a..b6fe434 100644
--- a/src/mango/test/12-use-correct-index-test.py
+++ b/src/mango/test/12-use-correct-index-test.py
@@ -93,7 +93,7 @@ class ChooseCorrectIndexForDocs(mango.DbPerClass):
         self.assertEqual(explain_resp["index"]["type"], "special")
         resp = self.db.find(selector, return_raw=True)
         self.assertEqual(
-            resp["warning"][0].lower(),
+            resp["warning"].split('\n')[0].lower(),
             "no matching index found, create an index to optimize query time.",
         )