You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/06/10 19:52:22 UTC

[couchdb] 04/06: Fix validate_doc_update when recreating a document

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

davisp pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 5331966c20c516ed2fac9497b68d49047d6b72e9
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Jun 10 14:35:11 2019 -0500

    Fix validate_doc_update when recreating a document
    
    This fixes the behavior when validating a document update that is
    recreating a previously deleted document. Before this fix we were
    sending a document body with `"_deleted":true` as the existing document.
    However, CouchDB behavior expects the previous document passed to VDU's
    to be `null` in this case.
---
 src/fabric/src/fabric2_db.erl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index acd473f..48e50f1 100644
--- a/src/fabric/src/fabric2_db.erl
+++ b/src/fabric/src/fabric2_db.erl
@@ -1196,8 +1196,13 @@ prep_and_validate(Db, NewDoc, PrevRevInfo) ->
         _ -> false
     end,
 
+    WasDeleted = case PrevRevInfo of
+        not_found -> false;
+        #{deleted := D} -> D
+    end,
+
     PrevDoc = case HasStubs orelse (HasVDUs and not IsDDoc) of
-        true when PrevRevInfo /= not_found ->
+        true when PrevRevInfo /= not_found, not WasDeleted ->
             case fabric2_fdb:get_doc_body(Db, NewDoc#doc.id, PrevRevInfo) of
                 #doc{} = PDoc -> PDoc;
                 {not_found, _} -> nil