Will Holley created COUCHDB-3239:
------------------------------------

             Summary: incorrect ordering of results when using open_revs and 
latest=true
                 Key: COUCHDB-3239
                 URL: https://issues.apache.org/jira/browse/COUCHDB-3239
             Project: CouchDB
          Issue Type: Bug
          Components: Database Core
            Reporter: Will Holley


When fetching open_revs with latest=true for a conflicted document, the order 
of results is incorrect. For example, if I create a document with the rev tree:

{code}
                        4-d1
                        /
                3-c1
                /
        2-b1
        /
1-a 
        \
        2-b2
                \
                3-c2
{code}

and ask for {{open_revs=["2-b1","2-b2"]&latest=true}}, the response will return 
{{3-c2}} followed by {{4-d1}} - the reverse of what I'd expect.

Below is a test/reproduction executed against Couch 1.6.1 and 2.0.

1.6.1:
{code}
$ export COUCH_HOST="http://127.0.0.1:5984";

$ curl -XPUT "$COUCH_HOST/open_revs_test"
{"ok":true}

$ curl "$COUCH_HOST/open_revs_test/_bulk_docs" -H 
"Content-Type:application/json" -XPOST -d @docs.json
[]

# GET open_revs=["2-b1","2-b2"]
$ curl -H "Accept:application/json" 
"$COUCH_HOST/open_revs_test/mydoc?open_revs=%5B%222-b1%22%2C%222-b2%22%5D"
[{"ok":{"_id":"mydoc","_rev":"2-b1","value":"x-winning"}},{"ok":{"_id":"mydoc","_rev":"2-b2","value":"x-losing"}}]

# GET open_revs=["2-b1","2-b2"]&latest=true
$ curl -H "Accept:application/json" 
"$COUCH_HOST/open_revs_test/mydoc?open_revs=%5B%222-b1%22%2C%222-b2%22%5D"
[{"ok":{"_id":"mydoc","_rev":"4-d1","value":"z-winning"}},{"ok":{"_id":"mydoc","_rev":"3-c2","value":"y-losing"}}]
{code}

2.0:
{code}
$ export COUCH_HOST="http://127.0.0.1:15984";

$ curl -XPUT "$COUCH_HOST/open_revs_test"
{"ok":true}

$ curl "$COUCH_HOST/open_revs_test/_bulk_docs" -H 
"Content-Type:application/json" -XPOST -d @docs.json
[]

# GET open_revs=["2-b1","2-b2"]
$ curl -H "Accept:application/json" 
"$COUCH_HOST/open_revs_test/mydoc?open_revs=%5B%222-b1%22%2C%222-b2%22%5D"
[{"ok":{"_id":"mydoc","_rev":"2-b1","value":"x-winning"}},{"ok":{"_id":"mydoc","_rev":"2-b2","value":"x-losing"}}]

# GET open_revs=["2-b1","2-b2"]&latest=true
$ curl -H "Accept:application/json" 
"$COUCH_HOST/open_revs_test/mydoc?open_revs=%5B%222-b1%22%2C%222-b2%22%5D"
[{"ok":{"_id":"mydoc","_rev":"3-c2","value":"y-losing"}},{"ok":{"_id":"mydoc","_rev":"4-d1","value":"z-winning"}}]
{code}

Note the reversed order of the results in 2.0 when {{latest=true}} is specified.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to