You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/11/05 04:16:53 UTC

[GitHub] [couchdb] jiahuili430 opened a new pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

jiahuili430 opened a new pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819


   ## Overview
   Use `_bulk_docs` with "new_edits": false and without `_rev` should respond with 400 Bad Request instead of 500 Server Error.
   When "new_edits": false, the request should always include the value of `_rev`.
   
   **Ref:**
   [1] https://docs.couchdb.org/en/stable/api/document/common.html?highlight=%20use%20only%20by%20the%20replicato#put--db-docid
   [2] https://docs.couchdb.org/en/stable/api/database/bulk-api.html?highlight=bulk_docs#db-bulk-docs
   
   ## Testing recommendations
   **Manual testing:**
   
   If any documents don't have `_rev`, will raise **400 Bad Request**.
   ```
   $ curl -X POST $DB/demo/_bulk_docs \
     -H 'Content-Type: application/json' \
     -d '{
          "docs": [{"_id": "FishStew", "_rev": "1-1", "value": 1},
                   {"_id": "LambStew", "value": 2}],
          "new_edits": false
     }'
   {"error":"bad_request","reason":"`new_edits: false` is intended for use only by the replicator."}
   ```
   
   ## Related Issues or Pull Requests
   https://github.com/apache/couchdb/issues/2242
   
   ## Checklist
   
   - [ ] Code is written and works correctly
   - [ ] Changes are covered by tests
   - [ ] Any new configurable parameters are documented in `rel/overlay/etc/default.ini`
   - [ ] A PR for documentation changes has been made in https://github.com/apache/couchdb-documentation
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744882572



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1960,6 +1962,13 @@ validate_security_can_be_edited(DbName) ->
         {_,_} -> ok
     end.
 
+validate_revs(Doc, NewEdits) ->
+    if NewEdits =:= false andalso Doc#doc.revs =:= {0, []} ->
+        throw({bad_request, ?l2b("When `new_edits: false`, "
+        ++ "the document needs `_rev` or `_revisions` specified")});
+        true -> Doc

Review comment:
       We don't have to return `Doc` since we're not using it. Usually we'd return `ok` in such case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] jiahuili430 commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
jiahuili430 commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744911184



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1960,6 +1962,14 @@ validate_security_can_be_edited(DbName) ->
         {_,_} -> ok
     end.
 
+validate_revs(_Doc, true) ->
+    ok;
+validate_revs(#doc{revs = {0, []}}, false) ->
+    throw({bad_request, ?l2b("When `new_edits: false`, " ++
+    "the document needs `_rev` or `_revisions` specified")});

Review comment:
       added




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] jiahuili430 commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
jiahuili430 commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744775435



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->
+            Doc = couch_db:doc_from_json_obj_validate(Db, JsonObj),
+            Doc#doc.revs =:= {0, []} end, DocsArray) of
+        true ->
+            throw({bad_request, ?l2b("`new_edits: false` is "
+            "intended for use only by the replicator.")});

Review comment:
       Changed, thanks for the review!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] jiahuili430 commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
jiahuili430 commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744879920



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1960,6 +1962,13 @@ validate_security_can_be_edited(DbName) ->
         {_,_} -> ok
     end.
 
+validate_revs(Doc, NewEdits) ->
+    if NewEdits =:= false andalso Doc#doc.revs =:= {0, []} ->
+        throw({bad_request, ?l2b("When `new_edits: false`, "
+        ++ "the document needs `_rev` or `_revisions` information")});

Review comment:
       Changed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r743738276



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->
+            Doc = couch_db:doc_from_json_obj_validate(Db, JsonObj),

Review comment:
       We already ran through the `couch_db:doc_from_json_obj_validate(Db, JsonObj)` above, so wondering if we can't just re-use that instead of paying the performance penalty again

##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->

Review comment:
       The case format looks a bit odd, it's a bit nicer to have the `case Exp of` all in one line. So we might do the check first then have something like `case HasMissingRev of`.
   
   However, since we're throwing a `bad_request` anyway there is probably no reason to use a case statement. Just `lists:foreach(fun(Doc) -> ` might work?

##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->
+            Doc = couch_db:doc_from_json_obj_validate(Db, JsonObj),
+            Doc#doc.revs =:= {0, []} end, DocsArray) of
+        true ->
+            throw({bad_request, ?l2b("`new_edits: false` is "
+            "intended for use only by the replicator.")});

Review comment:
       The statement is true but doesn't help the user as much. For all we know they were trying to build their own replicator so it would be nice provide exact feedback on why we failed their request




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r743738276



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->
+            Doc = couch_db:doc_from_json_obj_validate(Db, JsonObj),

Review comment:
       We already ran through the `couch_db:doc_from_json_obj_validate(Db, JsonObj)` above, so wondering if we can't just re-use that instead of paying the performance penalty again




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744890731



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,7 +571,7 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
+        case fabric:update_docs(Db, Docs, [replicated_changes | Options]) of

Review comment:
       Normally this would be a good change, but it should be in a separate PR probably.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744872885



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1960,6 +1962,13 @@ validate_security_can_be_edited(DbName) ->
         {_,_} -> ok
     end.
 
+validate_revs(Doc, NewEdits) ->
+    if NewEdits =:= false andalso Doc#doc.revs =:= {0, []} ->
+        throw({bad_request, ?l2b("When `new_edits: false`, "
+        ++ "the document needs `_rev` or `_revisions` information")});

Review comment:
       A minor nit: It might sound better to say:
   ```
   it needs `_rev` or `_revisions` specified
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r743738276



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->
+            Doc = couch_db:doc_from_json_obj_validate(Db, JsonObj),

Review comment:
       We already ran through the `couch_db:doc_from_json_obj_validate(Db, JsonObj)` above, so wondering if we can't just re-use that instead of paying the performance penalty again

##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->

Review comment:
       The case format looks a bit odd, it's a bit nicer to have the `case Exp of` all in one line. So we might do the check first then have something like `case HasMissingRev of`.
   
   However, since we're throwing a `bad_request` anyway there is probably no reason to use a case statement. Just `lists:foreach(fun(Doc) -> ` might work?

##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->
+            Doc = couch_db:doc_from_json_obj_validate(Db, JsonObj),
+            Doc#doc.revs =:= {0, []} end, DocsArray) of
+        true ->
+            throw({bad_request, ?l2b("`new_edits: false` is "
+            "intended for use only by the replicator.")});

Review comment:
       The statement is true but doesn't help the user as much. For all we know they were trying to build their own replicator so it would be nice provide exact feedback on why we failed their request




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744898411



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1960,6 +1962,14 @@ validate_security_can_be_edited(DbName) ->
         {_,_} -> ok
     end.
 
+validate_revs(_Doc, true) ->
+    ok;
+validate_revs(#doc{revs = {0, []}}, false) ->
+    throw({bad_request, ?l2b("When `new_edits: false`, " ++
+    "the document needs `_rev` or `_revisions` specified")});

Review comment:
       Minor nit, indent this line by 4 spacs.

##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1960,6 +1962,14 @@ validate_security_can_be_edited(DbName) ->
         {_,_} -> ok
     end.
 
+validate_revs(_Doc, true) ->
+    ok;
+validate_revs(#doc{revs = {0, []}}, false) ->
+    throw({bad_request, ?l2b("When `new_edits: false`, " ++
+    "the document needs `_rev` or `_revisions` specified")});

Review comment:
       Minor nit, indent this line by 4 spaces




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r743743082



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->
+            Doc = couch_db:doc_from_json_obj_validate(Db, JsonObj),
+            Doc#doc.revs =:= {0, []} end, DocsArray) of
+        true ->
+            throw({bad_request, ?l2b("`new_edits: false` is "
+            "intended for use only by the replicator.")});

Review comment:
       The statement is true but doesn't help the user as much. For all we know they were trying to build their own replicator so it would be nice provide exact feedback on why we failed their request




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r743741699



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->

Review comment:
       The case format looks a bit odd, it's a bit nicer to have the `case Exp of` all in one line. So we might do the check first then have something like `case HasMissingRev of`.
   
   However, since we're throwing a `bad_request` anyway there is probably no reason to use a case statement. Just `lists:foreach(fun(Doc) -> ` might work?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] jiahuili430 commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
jiahuili430 commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744774258



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -569,15 +569,23 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
             send_json(Req, 417, ErrorsJson)
         end;
     false ->
-        case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
-        {ok, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 201, ErrorsJson);
-        {accepted, Errors} ->
-            chttpd_stats:incr_writes(length(Docs)),
-            ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors),
-            send_json(Req, 202, ErrorsJson)
+        case lists:any(fun(JsonObj) ->
+            Doc = couch_db:doc_from_json_obj_validate(Db, JsonObj),

Review comment:
       Good idea!
   Add a function `validate_revs(Doc, NewEdits)` after `couch_db:doc_from_json_obj_validate(Db, JsonObj)`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva commented on a change in pull request #3819: _bulk_docs and new_edits: false should only be used by the replicator

Posted by GitBox <gi...@apache.org>.
nickva commented on a change in pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819#discussion_r744885873



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1960,6 +1962,13 @@ validate_security_can_be_edited(DbName) ->
         {_,_} -> ok
     end.
 
+validate_revs(Doc, NewEdits) ->

Review comment:
       It might be simpler to check a few things directly in the function head
   
   ```
   validate_revs(_Doc, true) ->
       ok
   validate_revs(#doc{revs = {0, []}, false) ->
       throw({bad_request, ....})
   validate_revs(_Doc, false) ->
        ok




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [couchdb] nickva merged pull request #3819: _bulk_docs and new_edits: false should provide revision info

Posted by GitBox <gi...@apache.org>.
nickva merged pull request #3819:
URL: https://github.com/apache/couchdb/pull/3819


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org