Restore rev handling for _bulk_docs with all_or_nothing
authorRobert Newson <rnewson@apache.org>
Mon, 17 Jun 2013 10:05:01 +0000 (11:05 +0100)
committerRobert Newson <rnewson@apache.org>
Mon, 17 Jun 2013 14:29:16 +0000 (15:29 +0100)
commitdfd39d570f5f841ae5e003fc8b4a2073c267e89a
treee009fa5b05af1918a0b1b20c459765c673d30eb6
parent0bb6787cec9c986feb1f6c16a280f2c0506dec0d
Restore rev handling for _bulk_docs with all_or_nothing

Commit 5b1430c120904181313848444dbfcdb60e42568b added this hunk;

-        {aborted, lists:map(
-            fun({{Id,{Pos, [RevId|_]}}, Error}) ->
-                {{Id, {Pos, RevId}}, Error};
-            ({{Id,{0, []}}, Error}) ->
-                {{Id, {0, <<>>}}, Error}
-            end, PreCommitFailures)};
+        {aborted,
+         lists:foldl(fun({#doc{id=Id,revs={Pos, RevIds}}, Ref},Acc) ->
+                         case lists:keyfind(Ref,1,PreCommitFailures) of
+                         {Ref, Error} ->
+                             [{{Id,{Pos,RevIds}}, Error} | Acc];
+                         false ->
+                             Acc
+                         end
+                     end,[],Docs3)};
+

This causes the full list of revisions to be passed to revid_to_str/1;

revid_to_str(RevId) when size(RevId) =:= 16 ->
    ?l2b(couch_util:to_hex(RevId));
revid_to_str(RevId) ->
    RevId.

This falls through to the second case, which in turn leads to invalid
JSON output when we convert the presumed iolist.

This patch restores the code that takes only the head of the revisions
list when present, and an artificial "0-" when it is not (in the case
that the validation fails for a new document rather than an update).

BugzID: 1772
src/couchdb/couch_db.erl