Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCBC-450: Set value of subdoc exists to true or false if result is success or path-not-found #120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/couchbase
6 changes: 3 additions & 3 deletions ext/couchbase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,7 @@ cb_Backend_document_lookup_in(VALUE self, VALUE bucket, VALUE scope, VALUE colle
if (!resp_entry.value.empty()) {
rb_hash_aset(entry, value_property, cb_str_new(resp_entry.value));
}
if (resp_entry.ec && resp_entry.ec != couchbase::errc::key_value::path_not_found) {
if (resp_entry.ec) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for this check now that C++ clears path_not_found status codes for exists specs

rb_hash_aset(entry,
error_property,
cb_map_error_code(resp_entry.ec,
Expand Down Expand Up @@ -3628,7 +3628,7 @@ cb_Backend_document_lookup_in_any_replica(VALUE self, VALUE bucket, VALUE scope,
if (!resp_entry.value.empty()) {
rb_hash_aset(entry, value_property, cb_str_new(resp_entry.value));
}
if (resp_entry.ec && resp_entry.ec != couchbase::errc::key_value::path_not_found) {
if (resp_entry.ec) {
rb_hash_aset(entry,
error_property,
cb_map_error_code(resp_entry.ec,
Expand Down Expand Up @@ -3744,7 +3744,7 @@ cb_Backend_document_lookup_in_all_replicas(VALUE self, VALUE bucket, VALUE scope
if (!field_entry.value.empty()) {
rb_hash_aset(entry, value_property, cb_str_new(field_entry.value));
}
if (field_entry.ec && field_entry.ec != couchbase::errc::key_value::path_not_found) {
if (field_entry.ec) {
rb_hash_aset(
entry,
error_property,
Expand Down
3 changes: 1 addition & 2 deletions lib/couchbase/collection_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def content(path_or_index, transcoder = self.transcoder)
field = get_field_at_index(path_or_index)

raise field.error unless field.error.nil?
raise Error::PathNotFound, "Path is not found: #{path_or_index}" unless field.exists

transcoder.decode(field.value, :json)
end
Expand All @@ -191,7 +190,7 @@ def exists?(path_or_index)
end
return false unless field

raise field.error unless field.error.nil?
raise field.error unless field.error.nil? || field.error.is_a?(Error::PathNotFound)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core can return path_not_found status codes if those are coming from get or count operations. Those should not be raised if #exists is called - they should only be raised for #content


field.exists
end
Expand Down
25 changes: 19 additions & 6 deletions test/subdoc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,25 @@ def test_exists_single

@collection.upsert(doc_id, {"foo" => "bar"})

res = @collection.lookup_in(doc_id, [
LookupInSpec.exists("foo"),
])

assert res.exists?(0)
assert res.content(0)
end

def test_exists_single_does_not_exist
doc_id = uniq_id(:foo)

@collection.upsert(doc_id, {"foo" => "bar"})

res = @collection.lookup_in(doc_id, [
LookupInSpec.exists("does_not_exist"),
])

refute res.exists?(0)
assert_raises Error::PathNotFound do
res.content(0)
end
refute res.content(0)
end

def test_exists_multi
Expand All @@ -166,9 +177,7 @@ def test_exists_multi
])

refute res.exists?(0)
assert_raises Error::PathNotFound do
res.content(0)
end
refute res.content(0)

assert res.exists?(1)
assert_equal "bar", res.content(1)
Expand Down Expand Up @@ -1399,6 +1408,8 @@ def test_lookup_in_any_replica_exists

assert res.exists?(0)
refute res.exists?(1)
assert res.content(0)
refute res.content(1)
assert_respond_to res, :replica?
end

Expand All @@ -1421,6 +1432,8 @@ def test_lookup_in_all_replicas_exist
res.each do |entry|
assert entry.exists?(0)
refute entry.exists?(1)
assert entry.content(0)
refute entry.content(1)
assert_respond_to entry, :replica?
end
end
Expand Down