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

Invalid response to _bulk_docs with "all_or_nothing":true if validation fails

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.3
    • 1.4.0
    • Database Core
    • None

    Description

      When a document fails custom validation function while performing bulk document update with a all_or_nothing flag set the server responds with an ill-formed document revision id

      validation function:
      function (newDoc, oldDoc, userCtx) {
      if(newDoc.v && newDoc.v === 666){
      throw(

      {forbidden: '666'}

      );
      }
      }

      on a database 'test', using couchdb-python

      >>> doc={}
      >>> test.save(doc)
      ('04da7996f6503fca300cda889fd6e375', '1-967a00dff5e02add41819138abb3284d')
      >>> doc['v']=666
      >>> test.save(doc)

      Gives 403 error

      >>> test.update([doc])
      [(False, '04da7996f6503fca300cda889fd6e375', ServerError('666',))]

      Seems fine, too

      >>> test.update([doc], all_or_nothing=True)

      Now this gives exception in python that it can't parse json.
      >>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 51: invalid start byte

      the TCP stream:

      ===================================
      POST /test HTTP/1.1
      Host: 192.168.1.1:5984
      Transfer-Encoding: chunked
      Accept: application/json
      User-Agent: CouchDB-Python/0.9dev
      Content-Type: application/json

      2
      {}
      0

      HTTP/1.1 201 Created
      Server: CouchDB/1.3.0 (Erlang OTP/R15B)
      Location: http://192.168.1.1:5984/test/04da7996f6503fca300cda889fd6e375
      ETag: "1-967a00dff5e02add41819138abb3284d"
      Date: Tue, 16 Apr 2013 12:34:25 GMT
      Content-Type: application/json
      Content-Length: 95
      Cache-Control: must-revalidate

      {"ok":true,"id":"04da7996f6503fca300cda889fd6e375","rev":"1-967a00dff5e02add41819138abb3284d"}

      PUT /test/04da7996f6503fca300cda889fd6e375 HTTP/1.1
      Host: 192.168.1.1:5984
      Transfer-Encoding: chunked
      Accept: application/json
      User-Agent: CouchDB-Python/0.9dev
      Content-Type: application/json

      63

      {"_rev": "1-967a00dff5e02add41819138abb3284d", "_id": "04da7996f6503fca300cda889fd6e375", "v": 666}

      0

      HTTP/1.1 403 Forbidden
      Server: CouchDB/1.3.0 (Erlang OTP/R15B)
      Date: Tue, 16 Apr 2013 12:34:58 GMT
      Content-Type: application/json
      Content-Length: 37
      Cache-Control: must-revalidate

      {"error":"forbidden","reason":"666"}

      POST /test/_bulk_docs HTTP/1.1
      Host: 192.168.1.1:5984
      Transfer-Encoding: chunked
      Accept: application/json
      User-Agent: CouchDB-Python/0.9dev
      Content-Type: application/json

      6f
      {"docs": [

      {"_rev": "1-967a00dff5e02add41819138abb3284d", "_id": "04da7996f6503fca300cda889fd6e375", "v": 666}

      ]}
      0

      HTTP/1.1 201 Created
      Server: CouchDB/1.3.0 (Erlang OTP/R15B)
      Date: Tue, 16 Apr 2013 12:36:29 GMT
      Content-Type: application/json
      Content-Length: 79
      Cache-Control: must-revalidate

      [

      {"id":"04da7996f6503fca300cda889fd6e375","error":"forbidden","reason":"666"}

      ]

      POST /test/_bulk_docs HTTP/1.1
      Host: 192.168.1.1:5984
      Transfer-Encoding: chunked
      Accept: application/json
      User-Agent: CouchDB-Python/0.9dev
      Content-Type: application/json

      87
      {"all_or_nothing": true, "docs": [

      {"_rev": "1-967a00dff5e02add41819138abb3284d", "_id": "04da7996f6503fca300cda889fd6e375", "v": 666}

      ]}
      0

      HTTP/1.1 417 Expectation Failed
      Server: CouchDB/1.3.0 (Erlang OTP/R15B)
      Date: Tue, 16 Apr 2013 12:38:15 GMT
      Content-Type: application/json
      Content-Length: 111
      Cache-Control: must-revalidate

      [

      {"id":"04da7996f6503fca300cda889fd6e375","rev":"1-.z\u0000...*.A..8..(M","error":"forbidden","reason":"666"}

      ]
      =========================

      From couchdb log (debug)
      =================================
      [Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.11369.0>] 'POST' /test/_bulk_docs

      {1,1}

      from "192.168.1.54"
      Headers: [

      {'Accept',"application/json"}

      ,

      {'Content-Type',"application/json"}

      ,

      {'Host',"192.168.1.1:5984"}

      ,

      {'Transfer-Encoding',"chunked"}

      ,

      {'User-Agent',"CouchDB-Python/0.9dev"}

      ]
      [Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.11369.0>] OAuth Params: []
      [Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.109.0>] DDocProc found for DDocKey:

      {<<"_design/projects">>, <<"39-4232874e2956d9085f2d7aaf8567c3d9">>}

      [Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.353.0>] OS Process #Port<0.3439> Input :: ["reset",

      {"reduce_limit":true,"timeout":5000}

      ]
      [Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.353.0>] OS Process #Port<0.3439> Output :: true
      [Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.353.0>] OS Process #Port<0.3439> Input :: ["ddoc","_design/projects",["validate_doc_update"],[{"_id":"04da7996f6503fca300cda889fd6e375","_rev":"1-967a00dff5e02add41819138abb3284d","v":666,"_revisions":{"start":1,"ids":["967a00dff5e02add41819138abb3284d"]}},{"_id":"04da7996f6503fca300cda889fd6e375","_rev":"1-967a00dff5e02add41819138abb3284d","_revisions":{"start":1,"ids":["967a00dff5e02add41819138abb3284d"]}},

      {"db":"test","name":null,"roles":[]}

      ,{}]]
      [Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.353.0>] OS Process #Port<0.3439> Output ::

      {"forbidden":"666"}

      [Tue, 16 Apr 2013 12:38:15 GMT] [info] [<0.11369.0>] 192.168.1.54 - - POST /test/_bulk_docs 417
      [Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.11369.0>] httpd 417 error response:
      [

      {"id":"04da7996f6503fca300cda889fd6e375","rev":"1-<96>z\u0000<DF><F5><E0>*<DD>A<81><91>8<AB><B3>(M","error":"forbidden","reason":"666"}

      ]
      ================================

      As seen, there is something wrong with the way the 'rev' is serialized in the output.

      Attachments

        1. 1772.patch
          0.5 kB
          Leonid Usov

        Activity

          People

            rnewson Robert Newson
            leonid.s.usov Leonid Usov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: