Skip to content

Commit

Permalink
Fix No notification for write transaction that contains only change t…
Browse files Browse the repository at this point in the history
…o 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 <[email protected]>

* code review

* adding some more testing

* code review

Co-authored-by: James Stone <[email protected]>
  • Loading branch information
nicola-cab and ironage authored Dec 5, 2022
1 parent 80d8790 commit a4fafc1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](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.
Expand Down
6 changes: 5 additions & 1 deletion src/realm/object-store/impl/deep_change_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ void CollectionKeyPathChangeChecker::find_changed_columns(std::vector<ColKey>& 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);
}
Expand Down
32 changes: 32 additions & 0 deletions test/object-store/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit a4fafc1

Please sign in to comment.