apache / apache/openwhisk-package-cloudant
manage-bulk-documents action fails with incorrect Cloudant request body
- Dominant language
- Scala
- Stars
- 17
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
When I use the `manage-bulk-documents` action, it fails because the query sent to Cloudant is not a JSON object. The action expects a JSON object with a `docs` key that contains an array of documents and so does Cloudant. However, the action only sends the array without the container object and the `docs` key. So what Cloudant receives is:
```
[{"_id":"0399a368b906664af2d0e39de79a8ccf","_rev":"1-d55be7137d8447de7062c9ffed88341c","_deleted":true}]
```
while it expects:
```
{"docs":[{"_id":"0399a368b906664af2d0e39de79a8ccf","_rev":"1-d55be7137d8447de7062c9ffed88341c","_deleted":true}]}
```
The action should retain the container object with the `docs` key to ensure that what is passed to Cloudant is correct.
## Steps to reproduce
Send the `manage-bulk-documents` action a query like:
```
{
"docs": [ actual docs go here ],
"dbname": "mydb"
}
```
It will fail with the error indicated below.
## Workaround
A workaround is to send the action an object like this:
```
{
"docs": {
"docs": [ actual docs go here ]
},
"dbname": "mydb"
}
```
## Error details
```
uri: "https://XXXXXX:XXXXXX@fd6333b7-4bdc-4170-bed8-ded48d9aab0f-bluemix.cloudant.com/codes-db/_bulk_docs",
body: "[{"_id":"0399a368b906664af2d0e39de79a8ccf","_rev":"1-d55be7137d8447de7062c9ffed88341c","_deleted":true}]"
},
description: "couch returned 400",
scope: "couch",
reason: "Request body must be a JSON object",
error: "bad_request",
stack: "Error: Request body must be a JSON object at Request._callback (/nodejsAction/node_modules/cloudant-nano/lib/nano.js:247:15) at Request.self.callback (/nodejsAction/node_modules/request/request.js:186:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (/nodejsAction/node_modules/request/request.js:1081:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at IncomingMessage. (/nodejsAction/node_modules/request/request.js:1001:12) at IncomingMessage.g (events.js:292:16)",
message: "Request body must be a JSON object",
errid: "non_200",
headers: {
statusCode: 400,
x-cloudant-request-class: "write",
cache-control: "must-revalidate",
uri: "https://XXXXXX:XXXXXX@fd6333b7-4bdc-4170-bed8-ded48d9aab0f-bluemix.cloudant.com/codes-db/_bulk_docs",
x-cloudant-backend: "bm-cc-uk-04",
date: "Fri, 13 Apr 2018 07:58:18 GMT",
content-type: "application/json",
via: "1.1 lb1.bm-cc-uk-04 (Glum/1.50.4)",
x-couch-request-id: "9564b6b77f",
x-frame-options: "DENY",
x-content-type-options: "nosniff",
strict-transport-security: "max-age=31536000"
}
}
},
success: false,
status: "application error"
},
cause: "a09af6f4223f42d69af6f4223f42d637",
end: 1523606299620,
logs: [
"2018-04-13T07:58:19.612240359Z stdout: Error: { Error: Request body must be a JSON object",
"2018-04-13T07:58:19.612292573Z stdout: at Request._callback (/nodejsAction/node_modules/cloudant-nano/lib/nano.js:247:15)",
"2018-04-13T07:58:19.612318225Z stdout: at Request.self.callback (/nodejsAction/node_modules/request/request.js:186:22)",
"2018-04-13T07:58:19.612326284Z stdout: at emitTwo (events.js:106:13)",
"2018-04-13T07:58:19.612332269Z stdout: at Request.emit (events.js:191:7)",
"2018-04-13T07:58:19.612338124Z stdout: at Request. (/nodejsAction/node_modules/request/request.js:1081:10)",
"2018-04-13T07:58:19.612344609Z stdout: at emitOne (events.js:96:13)",
"2018-04-13T07:58:19.612350314Z stdout: at Request.emit (events.js:188:7)",
"2018-04-13T07:58:19.612356059Z stdout: at IncomingMessage. (/nodejsAction/node_modules/request/request.js:1001:12)",
"2018-04-13T07:58:19.612362053Z stdout: at IncomingMessage.g (events.js:292:16)",
"2018-04-13T07:58:19.6123677Z stdout: name: 'Error',",
"2018-04-13T07:58:19.61237329Z stdout: error: 'bad_request',",
"2018-04-13T07:58:19.612378858Z stdout: reason: 'Request body must be a JSON object',",
"2018-04-13T07:58:19.612384286Z stdout: scope: 'couch',",
"2018-04-13T07:58:19.612389608Z stdout: statusCode: 400,",
"2018-04-13T07:58:19.612395147Z stdout: request:",
"2018-04-13T07:58:19.612400364Z stdout: { method: 'POST',",
"2018-04-13T07:58:19.612405802Z stdout: headers:",
"2018-04-13T07:58:19.612411188Z stdout: { 'content-type': 'application/json',",
"2018-04-13T07:58:19.612416727Z stdout: accept: 'application/json' },",
"2018-04-13T07:58:19.612422952Z stdout: uri: 'https://XXXXXX:XXXXXX@fd6333b7-4bdc-4170-bed8-ded48d9aab0f-bluemix.cloudant.com/codes-db/_bulk_docs',",
"2018-04-13T07:58:19.612428666Z stdout: body: '[{"_id":"0399a368b906664af2d0e39de79a8ccf","_rev":"1-d55be7137d8447de7062c9ffed88341c","_deleted":true}]' },",
"2018-04-13T07:58:19.612435273Z stdout: headers:",
"2018-04-13T07:58:19.612440656Z stdout: { 'cache-control': 'must-revalidate',",
"2018-04-13T07:58:19.612446081Z stdout: 'content-type': 'application/json',",
"2018-04-13T07:58:19.612451549Z stdout: date: 'Fri, 13 Apr 2018 07:58:18 GMT',",
"2018-04-13T07:58:19.612456953Z stdout: 'x-couch-request-id': '9564b6b77f',",
"2018-04-13T07:58:19.61246244Z stdout: 'x-frame-options': 'DENY',",
"2018-04-13T07:58:19.612467943Z stdout: 'strict-transport-security': 'max-age=31536000',",
"2018-04-13T07:58:19.612473238Z stdout: 'x-content-type-options': 'nosniff',",
"2018-04-13T07:58:19.61247879Z stdout: 'x-cloudant-request-class': 'write',",
"2018-04-13T07:58:19.612484218Z stdout: 'x-cloudant-backend': 'bm-cc-uk-04',",
"2018-04-13T07:58:19.612489575Z stdout: via: '1.1 lb1.bm-cc-uk-04 (Glum/1.50.4)',",
"2018-04-13T07:58:19.612495081Z stdout: statusCode: 400,",
"2018-04-13T07:58:19.61250041Z stdout: uri: 'https://XXXXXX:XXXXXX@fd6333b7-4bdc-4170-bed8-ded48d9aab0f-bluemix.cloudant.com/codes-db/_bulk_docs' },",
"2018-04-13T07:58:19.612511338Z stdout: errid: 'non_200',",
"2018-04-13T07:58:19.612521052Z stdout: description: 'couch returned 400' }"
],
start: 1523606299173,
namespace: "consideratehoteliers.com_dev"
}
```
Contributor guide
Assessment
This issue has not been assessed yet.