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

RCORE-2167: C API: Fix empty keypath issue #7986

Merged
merged 1 commit into from
Aug 15, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* None.
* Using an empty KeyPath in C API would result in no filtering being done ([#7805](https://github.com/realm/realm-core/issues/7805))

### Breaking changes
* None.
Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/c_api/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct DictionaryNotificationsCallback {
std::optional<KeyPathArray> build_key_path_array(realm_key_path_array_t* key_path_array)
{
std::optional<KeyPathArray> ret;
if (key_path_array && key_path_array->size()) {
if (key_path_array) {
Copy link
Member

Choose a reason for hiding this comment

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

arg, subtle... nice catch!!!

ret.emplace(std::move(*key_path_array));
}
return ret;
Expand Down
14 changes: 10 additions & 4 deletions test/object-store/c_api/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,7 @@ TEST_CASE("C API - properties", "[c_api]") {
SECTION("Embedded objects") {
realm_property_info_t info;
bool found = false;
bool to_be_called = true;
realm_key_path_array_t* key_path_array = nullptr;
realm_find_property(realm, class_bar.key, "sub", &found, &info);
auto bar_sub_key = info.key;
Expand All @@ -3140,11 +3141,14 @@ TEST_CASE("C API - properties", "[c_api]") {
embedded = cptr_checked(realm_set_embedded(obj2.get(), bar_sub_key));
});

SECTION("using empty keypath") {
const char* bar_strings[1] = {""};
key_path_array = realm_create_key_path_array(realm, class_bar.key, 0, bar_strings);
to_be_called = false;
}
SECTION("using valid nesting") {

const char* bar_strings[1] = {"sub.int"};
key_path_array = realm_create_key_path_array(realm, class_bar.key, 1, bar_strings);
REQUIRE(key_path_array);
}
SECTION("using star notation") {
const char* bar_strings[1] = {"*.int"};
Expand All @@ -3160,12 +3164,14 @@ TEST_CASE("C API - properties", "[c_api]") {
checked(realm_refresh(realm, nullptr));

state.called = false;
state.changes = nullptr;
write([&]() {
checked(realm_set_value(embedded.get(), embedded_int_key, rlm_int_val(999), false));
});
REQUIRE(state.called);
REQUIRE(state.called == to_be_called);
CHECK(!state.error);
CHECK(state.changes);
if (to_be_called)
CHECK(state.changes);
}
SECTION("using backlink") {
const char* bar_strings[1] = {"linking_objects.public_int"};
Expand Down
Loading