From a4fafc1027bf9ac150bf54990f6c0b397f28b223 Mon Sep 17 00:00:00 2001 From: nicola cabiddu Date: Mon, 5 Dec 2022 15:59:32 +0000 Subject: [PATCH] Fix No notification for write transaction that contains only change to backlink property (#6074) * notify backlink object in case of modifications * entry in the changelog * Update test/object-store/object.cpp Co-authored-by: James Stone * code review * adding some more testing * code review Co-authored-by: James Stone --- CHANGELOG.md | 1 + .../object-store/impl/deep_change_checker.cpp | 6 +++- test/object-store/object.cpp | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9893d1d7cf0..7d019fd04da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixed * ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?) * Fixed `realm_add_realm_refresh_callback` and notify immediately that there is not transaction snapshot to advance to. ([#6075](https://github.com/realm/realm-core/issues/6075), since v12.6.0) +* Fix no notification for write transaction that contains only change to backlink property. ([#4994](https://github.com/realm/realm-core/issues/4994), since v11.4.1) ### Breaking changes * FLX Subscription API reworked to better match SDK consumption patterns ([#6065](https://github.com/realm/realm-core/pull/6065)). Not all changes are breaking, but listing them all here together. diff --git a/src/realm/object-store/impl/deep_change_checker.cpp b/src/realm/object-store/impl/deep_change_checker.cpp index 4b72972c8ff..daa8d9a7161 100644 --- a/src/realm/object-store/impl/deep_change_checker.cpp +++ b/src/realm/object-store/impl/deep_change_checker.cpp @@ -397,7 +397,11 @@ void CollectionKeyPathChangeChecker::find_changed_columns(std::vector& c auto last_column_key = last_key_path_element.second; if (last_column_key.get_type() == col_type_BackLink) { auto iterator = m_info.tables.find(table.get_key()); - if (iterator != m_info.tables.end() && !iterator->second.insertions_empty()) { + auto table_has_changed = [iterator] { + return !iterator->second.insertions_empty() || !iterator->second.modifications_empty() || + !iterator->second.deletions_empty(); + }; + if (iterator != m_info.tables.end() && table_has_changed()) { ColKey root_column_key = key_path[0].second; changed_columns.push_back(root_column_key); } diff --git a/test/object-store/object.cpp b/test/object-store/object.cpp index 9725685505c..d25f7dac8fc 100644 --- a/test/object-store/object.cpp +++ b/test/object-store/object.cpp @@ -914,6 +914,38 @@ TEST_CASE("object") { REQUIRE(change.columns.size() == 1); REQUIRE_INDICES(change.columns[col_target_backlink.value], 0); } + SECTION("changes to backlink are reported both to origin and destination object") { + Object object_origin2; + write([&] { + Obj obj_origin2 = table_origin->create_object_with_primary_key(300); + object_origin2 = Object{r, obj_origin2}; + }); + + // add a backlink + auto token_with_backlink = require_change(object_target, key_path_array_target_backlink); + write([&] { + object_origin2.set_property_value(d, "link", util::Any(object_target)); + }); + REQUIRE_INDICES(change.modifications, 0); + REQUIRE(change.columns.size() == 1); + REQUIRE_INDICES(change.columns[col_target_backlink.value], 0); + + // nullify a backlink + write([&] { + object_origin2.set_property_value(d, "link", std::any()); + }); + REQUIRE_INDICES(change.modifications, 0); + REQUIRE(change.columns.size() == 1); + REQUIRE_INDICES(change.columns[col_target_backlink.value], 0); + + // remove a backlink + write([&] { + table_origin->remove_object(object_origin2.obj().get_key()); + }); + REQUIRE_INDICES(change.modifications, 0); + REQUIRE(change.columns.size() == 1); + REQUIRE_INDICES(change.columns[col_target_backlink.value], 0); + } } }