Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.3
-
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(
);
}
}
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
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
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": [
]}
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": [
]}
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
from "192.168.1.54"
Headers: [
,
,
,
,
]
[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:
[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"]}},
,{}]]
[Tue, 16 Apr 2013 12:38:15 GMT] [debug] [<0.353.0>] OS Process #Port<0.3439> Output ::
[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:
[
]
================================
As seen, there is something wrong with the way the 'rev' is serialized in the output.