[RCBC-58] CAS block error Created: 17/Jul/12 Updated: 13/Nov/12 Resolved: 17/Jul/12 |
|
| Status: | Closed |
| Project: | Couchbase Ruby client library |
| Component/s: | library |
| Affects Version/s: | 1.0.0 |
| Fix Version/s: | None |
| Security Level: | Public |
| Type: | Bug | Priority: | Major |
| Reporter: | Karen Zeller | Assignee: | Sergey Avseyev |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: | Mac OSX, couchbase (1.1.2) | ||
| Description |
|
Unexpected CAS error:
Expected output from: cb.default_format = :document cb.set("trans1", "{'karen': '400', 'dipti': '800', 'status':'init' }")=> 360287970189639680 cb.cas("trans1") do |val| val["new"] = "new" val end Would be {'karen': '400', 'dipti': '800', 'status':'init', 'new': 'new' } but it returns: IndexError: string not matched from (irb):7:in `[]=' This is based on the rdoc example: c.default_format = :document c.set("foo", {"bar" => 1}) c.cas("foo") do |val| val["baz"] = 2 val end c.get("foo") #=> {"bar" => 1, "baz" => 2} |
| Comments |
| Comment by Sergey Avseyev [ 17/Jul/12 ] |
|
It isn't bug here Note what are you setting as document: "{'karen': '400', 'dipti': '800', 'status':'init' }" This is a String, so it will be encoded as JSON string. If you'd like to store a JSON Object, you should use Ruby Hash: {'karen' => '400', 'dipti' => '800', 'status' => 'init' } I guess '400' and '800' shouldn't be specified as strings, therefore you might want to omit single quotes |
| Comment by Matt Ingenthron [ 18/Jul/12 ] |
|
Also note that quoting JSON with ' is actually not legal. It's supposed to be " . Some JSON parsers (particularly some Python libraries) are really lax about this, but what you have there isn't JSON. It's a semi-JSON like string.
See json.org |
| Comment by Karen Zeller [ 18/Jul/12 ] |
| I will add this last point to the section on Using JSON docs in the Structuring Data chapter of dev. guide.... |