openwhisk-package-cloudant icon indicating copy to clipboard operation
openwhisk-package-cloudant copied to clipboard

Write with Overwrite = true fails if doc doesn't exist

Open tleyden opened this issue 7 years ago • 2 comments

If you do a write with --param overwrite 'true' on a non-existent doc id:

wsk action invoke cloudant/write --blocking --result --param overwrite 'true' --param doc '{"foo": "bar", "_id": "nonexistent_docid"}'

it gives an error:

        "stack": "Error: missing\n    at Request._callback (/nodejsAction/node_modules/cloudant-nano/lib/nano.js:247:15)\n    at Request.self.callback (/nodejsAction/node_modules/request/request.js:186:22)\n    at emitTwo (events.js:106:13)\n    at Request.emit (events.js:191:7)\n    at Request.<anonymous> (/nodejsAction/node_modules/request/request.js:1081:10)\n    at emitOne (events.js:96:13)\n    at Request.emit (events.js:188:7)\n    at IncomingMessage.<anonymous> (/nodejsAction/node_modules/request/request.js:1001:12)\n    at IncomingMessage.g (events.js:291:16)",
        "statusCode": 404

But if I remove the --param overwrite 'true', it works. And then subsequent writes with --param overwrite 'true' succeed and update the revision.

In this case, I think it's safe to ignore the 404 error trying to do the GET to fetch the existing revision, since it's expected that it might be the first revision, and no existing revisions exist.

tleyden avatar Jul 06 '17 05:07 tleyden

#110 is a related issue.

daisy-ycguo avatar Jul 06 '17 05:07 daisy-ycguo

Here's a rough golang version that works as I would expect in terms of writing a new doc or overwriting an existing doc

tleyden avatar Jul 06 '17 06:07 tleyden