You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2021/07/13 15:37:33 UTC

[couchdb] branch main updated: Fix "error":"case_clause" using latest=true

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new 2845461  Fix "error":"case_clause" using latest=true
2845461 is described below

commit 284546167a0240e272229c9c8f9beecb69681cd9
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Tue Jul 13 03:18:43 2021 -0400

    Fix "error":"case_clause" using latest=true
    
    This is a port of
    https://github.com/apache/couchdb/pull/3424/commits/a8622f0cca40d8f2338ec24b40f14d013a0f69d4
    to main
    
    Issue #3424
---
 src/chttpd/src/chttpd_db.erl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index df609bb..0c9d0ed 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -1076,7 +1076,7 @@ db_doc_req(#httpd{method = 'DELETE'} = Req, Db, DocId) ->
     send_updated_doc(Req, Db, DocId, Doc);
 db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
     #doc_query_args{
-        rev = Rev,
+        rev = Rev0,
         open_revs = Revs,
         options = Options,
         atts_since = AttsSince
@@ -1090,6 +1090,13 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
                     true ->
                         Options
                 end,
+            Rev =
+                case lists:member(latest, Options) of
+                    % couch_doc_open will open the winning rev despite of a rev passed
+                    % https://docs.couchdb.org/en/stable/api/document/common.html?highlight=latest#get--db-docid
+                    true -> nil;
+                    false -> Rev0
+                end,
             Doc = couch_doc_open(Db, DocId, Rev, Options2),
             send_doc(Req, Doc, Options2);
         _ ->