marten-de-vries opened a new issue #3362:
URL: https://github.com/apache/couchdb/issues/3362
## Description
When you have a document history like this:
```
1-a
/ \
2-b 2-c
```
A call to ```GET /db/doc?rev=1-a``` will result in a crash:
```
[error] 2021-02-06T23:21:33.513461Z nonode@nohost <0.6228.12> a58fb3a6be
req_err(1197101422) case_clause : {ok,[{ok,{doc,<<"doc">>,
{2,
[<<"6.+̻A�v�bU��Aj�">>,
<<150,122,0,223,245,224,42,221,65,129,145,56,171,179,40,77>>]},
{[{<<"db">>,2}]},
[],false,[]}},
{ok,{doc,<<"doc">>,
{2,
[<<132,154,113,198,77,133,144,218,50,17,7,241,51,175,79,6>>,
<<150,122,0,223,245,224,42,221,65,129,145,56,171,179,40,77>>]},
{[{<<"db">>,1}]},
[],false,[]}}]}
[<<"chttpd_db:couch_doc_open/4 L1410">>,<<"chttpd_db:db_doc_req/3
L928">>,<<"chttpd:handle_req_after_auth/2 L323">>,<<"chttpd:process_request/1
L306">>,<<"chttpd:handle_request_int/1 L244">>,<<"mochiweb_http:headers/6
L150">>,<<"proc_lib:init_p_do_apply/3 L247">>]
[notice] 2021-02-06T23:21:33.513848Z nonode@nohost <0.6228.12> a58fb3a6be
localhost:5984 127.0.0.1 marten GET
/db1/doc?rev=1-967a00dff5e02add41819138abb3284d&latest=true 500 ok 2
```
## Steps to Reproduce
Long but realistic version:
```bash
set -x
HOST=http://marten:test@localhost:5984
FIRST_REV=1-967a00dff5e02add41819138abb3284d
# create db1 and write common ancestor revision
curl -X PUT "$HOST/db1"
curl -X PUT "$HOST/db1/doc" -d {}
# replicate to (newly created) db2
curl -X POST "$HOST/_replicate" -d "{\"source\": \"${HOST}/db1\",
\"target\": \"${HOST}/db2\", \"create_target\": true}" -H "Content-Type:
application/json"
# update doc differently in both databases
curl -X PUT $HOST/db1/doc -d "{\"_id\": \"doc\", \"_rev\": \"$FIRST_REV\",
\"db\": 1}"
curl -X PUT $HOST/db2/doc -d "{\"_id\": \"doc\", \"_rev\": \"$FIRST_REV\",
\"db\": 2}"
# replicate db2 back to db1
curl -X POST "$HOST/_replicate" -d "{\"source\": \"${HOST}/db2\",
\"target\": \"${HOST}/db1\"}" -H "Content-Type: application/json"
# ... now make latest=true crash:
curl "$HOST/db1/doc?rev=${FIRST_REV}&latest=true"
# cleanup
curl -X DELETE "$HOST/db1"
curl -X DELETE "$HOST/db2"
```
A shorter but more artificial reproduction:
```
curl -X PUT "$HOST/db1"
curl -X POST "$HOST/db1/_bulk_docs" -H "Content-Type: application/json" -d
'{"docs": [{"_id": "doc1", "_rev": "1-a"}, {"_id": "doc1", "_rev": "2-b",
"_revisions": {"start": 2, "ids": ["b", "a"]}}, {"_id": "doc1", "_rev": "2-c",
"_revisions": {"start": 2, "ids": ["c", "a"]}}], "new_edits": false}'
curl "$HOST/db1/doc1?rev=1-a&latest=true"
curl -X DELETE "$HOST/db1"
```
## Expected Behaviour
I'd expect two documents to be returned, similar to ``curl
"$HOST/db1/doc1?open_revs=%5B%221-a%22%5D&latest=true"``. That might be
confusing to users expecting rev=? to return a single document, though. You'd
suddenly get a JSON array of objects instead of a single object when
``Content-Type`` is set to ``application/json``. PouchDB currently returns a
single document instead ('2-c').
## Your Environment
```json
{
"version": "3.1.1",
"git_sha": "ce596c65d",
"features": [
"access-ready",
"partitioned",
"pluggable-storage-engines",
"reshard",
"scheduler"
],
"vendor": {
"name": "The Apache Software Foundation"
}
}
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]