Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-3239

incorrect ordering of results when using open_revs and latest=true

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 2.0.0
    • None
    • Database Core
    • None

    Description

      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:

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

      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:

      $ 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&latest=true"
      [{"ok":{"_id":"mydoc","_rev":"4-d1","value":"z-winning"}},{"ok":{"_id":"mydoc","_rev":"3-c2","value":"y-losing"}}]
      

      2.0:

      $ 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&latest=true"
      [{"ok":{"_id":"mydoc","_rev":"3-c2","value":"y-losing"}},{"ok":{"_id":"mydoc","_rev":"4-d1","value":"z-winning"}}]
      

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

      Attachments

        1. docs.json
          1 kB
          Will Holley

        Activity

          People

            Unassigned Unassigned
            wilhol Will Holley
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: