What is the Issue?
There is an apparent contradiction between Emo's never-null doc get api and conditional application.
How to Test and Verify
-
Start Emo and run through this scenario:
-
I start out by deleting the doc so we know it doesn't exist...
$ http DELETE :8080/sor/1/review:testcustomer/testdoc000 audit=="comment:'blah'" X-BV-API-Key:local_admin Content-Type:application/x.json-delta
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 08 Feb 2017 15:07:46 GMT
Transfer-Encoding: chunked
{
"success": true
}
- I get the doc so you can see the state of it. Notice that there is no "nofield" attribute.
$ http GET :8080/sor/1/review:testcustomer/testdoc000 X-BV-API-Key:local_admin
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 08 Feb 2017 15:07:50 GMT
Transfer-Encoding: chunked
{
"client": "TestCustomer",
"type": "review",
"~deleted": true,
"~firstUpdateAt": "2017-02-08T15:06:10.121Z",
"~id": "testdoc000",
"~lastUpdateAt": "2017-02-08T15:07:46.685Z",
"~signature": "233b2c5fcc29921f9728a317d5398b07",
"~table": "review:testcustomer",
"~version": 2
}
- Since the "nofield" attribute is missing, I'd expect '{.., "nofield": ~}' to evaluate to true...
$ http POST :8080/sor/1/review:testcustomer/testdoc000 audit=="comment:'blah'" X-BV-API-Key:local_admin Content-Type:application/x.json-delta <<< 'if {..,"nofield":~} then {"author":"Fred","title":"Best Ever!","rating":5} end'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 08 Feb 2017 15:07:59 GMT
Transfer-Encoding: chunked
{
"success": true
}
- But it didn't!!!
$ http GET :8080/sor/1/review:testcustomer/testdoc000 X-BV-API-Key:local_admin
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 08 Feb 2017 15:08:04 GMT
Transfer-Encoding: chunked
{
"client": "TestCustomer",
"type": "review",
"~deleted": true,
"~firstUpdateAt": "2017-02-08T15:06:10.121Z",
"~id": "testdoc000",
"~lastUpdateAt": "2017-02-08T15:07:59.769Z",
"~signature": "618e69f4f5592b4b9a39df057d3dbf51",
"~table": "review:testcustomer",
"~version": 3
}
- But if I add a condition that the document itself may be missing...
$ http POST :8080/sor/1/review:testcustomer/testdoc000 audit=="comment:'blah'" X-BV-API-Key:local_admin Content-Type:application/x.json-delta <<< 'if or(~, {..,"nofield":~}) then {"author":"Fred","title":"Best Ever!","rating":5} end'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 08 Feb 2017 15:08:31 GMT
Transfer-Encoding: chunked
{
"success": true
}
- Then it works
$ http GET :8080/sor/1/review:testcustomer/testdoc000 X-BV-API-Key:local_admin
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 08 Feb 2017 15:08:33 GMT
Transfer-Encoding: chunked
{
"author": "Fred",
"client": "TestCustomer",
"rating": 5,
"title": "Best Ever!",
"type": "review",
"~deleted": false,
"~firstUpdateAt": "2017-02-08T15:06:10.121Z",
"~id": "testdoc000",
"~lastUpdateAt": "2017-02-08T15:08:31.106Z",
"~signature": "582736be3895778a4cc2e1286ba6ffb6",
"~table": "review:testcustomer",
"~version": 4
}
- Now that the document exists, my original conditional works as expected
$ http POST :8080/sor/1/review:testcustomer/testdoc000 audit=="comment:'blah'" X-BV-API-Key:local_admin Content-Type:application/x.json-delta <<< 'if {..,"nofield":~} then {"author":"Kenny","title":"Best Ever!","rating":5} end'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 08 Feb 2017 15:14:14 GMT
Transfer-Encoding: chunked
{
"success": true
}
- See?
$ http GET :8080/sor/1/review:testcustomer/testdoc000 X-BV-API-Key:local_admin
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 08 Feb 2017 15:14:16 GMT
Transfer-Encoding: chunked
{
"author": "Kenny",
"client": "TestCustomer",
"rating": 5,
"title": "Best Ever!",
"type": "review",
"~deleted": false,
"~firstUpdateAt": "2017-02-08T15:06:10.121Z",
"~id": "testdoc000",
"~lastUpdateAt": "2017-02-08T15:14:14.226Z",
"~signature": "01c5de13fdf7fe5dc27ca6852226ee68",
"~table": "review:testcustomer",
"~version": 5
}
Risk
Level
Low
: I can just always use the redundant conditional or(~, {..,"nofield":~})
. New users will find this behavior confusing, though... 'cause it is ;)
Issue Checklist