Skip to content

Commit

Permalink
Do not populate list KVO information for non-list collections (#7378)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Feb 26, 2024
1 parent 34bf170 commit 5ea7da5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
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.
* List KVO information was being populated for non-list collections ([PR #7378](https://github.com/realm/realm-core/pull/7378), since v14.0.0)

### Breaking changes
* None.
Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/impl/transact_log_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ KVOAdapter::KVOAdapter(std::vector<BindingContext::ObserverState>& observers, Bi
for (auto& observer : observers) {
auto table = group.get_table(TableKey(observer.table_key));
for (auto key : table->get_column_keys()) {
if (key.is_collection()) {
if (key.is_list()) {
m_lists.push_back({&observer, {}, {key}});
}
}
Expand Down
24 changes: 20 additions & 4 deletions test/object-store/realm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,13 @@ TEST_CASE("SharedRealm: async writes") {
TestFile config;
config.schema_version = 0;
config.schema = Schema{
{"object", {{"value", PropertyType::Int}, {"ints", PropertyType::Array | PropertyType::Int}}},
{"object",
{
{"value", PropertyType::Int},
{"ints", PropertyType::Array | PropertyType::Int},
{"int set", PropertyType::Set | PropertyType::Int},
{"int dictionary", PropertyType::Dictionary | PropertyType::Int},
}},
};
bool done = false;
auto realm = Realm::get_shared_realm(config);
Expand Down Expand Up @@ -2238,11 +2244,17 @@ TEST_CASE("SharedRealm: async writes") {
}
SECTION("object change information") {
realm->begin_transaction();
auto col = table->get_column_key("ints");
auto list_col = table->get_column_key("ints");
auto set_col = table->get_column_key("int set");
auto dict_col = table->get_column_key("int dictionary");
auto obj = table->create_object();
auto list = obj.get_list<Int>(col);
auto list = obj.get_list<Int>(list_col);
for (int i = 0; i < 3; ++i)
list.add(i);
auto set = obj.get_set<Int>(set_col);
set.insert(0);
auto dict = obj.get_dictionary(dict_col);
dict.insert("a", 0);
realm->commit_transaction();

Observer observer(obj);
Expand All @@ -2251,10 +2263,14 @@ TEST_CASE("SharedRealm: async writes") {

realm->async_begin_transaction([&]() {
list.clear();
set.clear();
dict.clear();
done = true;
});
wait_for_done();
REQUIRE(observer.array_change(0, col) == IndexSet{0, 1, 2});
REQUIRE(observer.array_change(0, list_col) == IndexSet{0, 1, 2});
REQUIRE(observer.array_change(0, set_col) == IndexSet{});
REQUIRE(observer.array_change(0, dict_col) == IndexSet{});
realm->m_binding_context.release();
}

Expand Down

0 comments on commit 5ea7da5

Please sign in to comment.