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

Support assigning nested collections via templated API #7478

Merged
merged 14 commits into from
Apr 25, 2024

Conversation

jedelbo
Copy link
Contributor

@jedelbo jedelbo commented Mar 14, 2024

What, How & Why?

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • C-API, if public C++ API changed
  • bindgen/spec.yml, if public C++ API changed

@cla-bot cla-bot bot added the cla: yes label Mar 14, 2024
@jedelbo jedelbo force-pushed the je/nested-collection-accessor branch from eef764f to e6fae70 Compare March 14, 2024 13:14
Copy link

coveralls-official bot commented Mar 14, 2024

Pull Request Test Coverage Report for Build jorgen.edelbo_192

Details

  • 464 of 474 (97.89%) changed or added relevant lines in 7 files are covered.
  • 2064 unchanged lines in 77 files lost coverage.
  • Overall coverage increased (+0.08%) to 91.854%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/primitive_list.cpp 0 3 0.0%
src/realm/object-store/object_accessor.hpp 247 254 97.24%
Files with Coverage Reduction New Missed Lines %
src/realm/index_string.cpp 1 87.52%
src/realm/object-store/sync/mongo_database.cpp 1 50.0%
src/realm/object-store/sync/sync_session.hpp 1 94.12%
src/realm/sync/network/default_socket.hpp 1 94.12%
src/realm/sync/socket_provider.hpp 1 87.5%
src/realm/util/uri.cpp 1 99.47%
test/fuzz_tester.hpp 1 59.58%
test/object-store/sync/session/wait_for_completion.cpp 1 98.77%
test/test_index_string.cpp 1 94.63%
src/realm/object-store/c_api/realm.cpp 2 70.37%
Totals Coverage Status
Change from base Build 2227: 0.08%
Covered Lines: 244196
Relevant Lines: 265853

💛 - Coveralls

@jedelbo jedelbo force-pushed the je/nested-collection-accessor branch from e6fae70 to 9eaf6c3 Compare March 14, 2024 14:44
@jedelbo jedelbo force-pushed the je/nested-collection-accessor branch from f3563f3 to 768ab8a Compare March 18, 2024 09:18
@jedelbo jedelbo marked this pull request as ready for review April 8, 2024 07:42
@jedelbo jedelbo requested a review from tgoyne April 8, 2024 07:42
} // namespace object_store
} // namespace realm

#include <realm/object-store/list.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

Why is this include here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of the mutural dependency between Dictionary and List, it must be included after the definition of Dictionary.

@@ -156,6 +156,13 @@ void Collection::validate_embedded(Context& ctx, T&& value, CreatePolicy policy)
throw IllegalOperation(util::format("Cannot add an existing managed embedded object to a %1.", type_name()));
}

// Dummy implementation to satisfy StringifyingContext
inline std::ostream& operator<<(std::ostream& out, const Collection&)
Copy link
Member

Choose a reason for hiding this comment

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

This should go in a test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -178,6 +184,41 @@ inline Obj Dictionary::get<Obj>(StringData key) const
return get_object(key);
}

namespace {
Copy link
Member

Choose a reason for hiding this comment

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

This is an ODR violation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched bact to just using a lambda.

attr_changed = !new_val.is_same_type(*old_val);
}

attr_changed = attr_changed || new_val != *old_val;
Copy link
Member

Choose a reason for hiding this comment

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

attr_changed is always false here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How is that?

sync_config.schema_version = 0;
server.start();
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any reason to be delaying starting the server here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this test has been run for a long time. I just tried to make it work, but did not really succeed. The test is still not run.

}

std::this_thread::sleep_for(std::chrono::milliseconds(5));
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be a proper wait rather than hoping that it's sleeping long enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just another attempt to get the test to work - but clearly not the right one.

if (m_type == PropertyType::Mixed) {
Mixed new_val = ctx.template unbox<Mixed>(value, policy);
if (new_val.is_type(type_Dictionary)) {
set_collection(list_ndx, CollectionType::Dictionary);
Copy link
Member

Choose a reason for hiding this comment

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

There appears to be a bunch of duplicated code between List and Dictionary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar, but not the same.

@jedelbo jedelbo force-pushed the je/nested-collection-accessor branch from f70bf10 to 0f798cb Compare April 9, 2024 14:00
@jedelbo jedelbo requested a review from tgoyne April 9, 2024 14:23
@jedelbo
Copy link
Contributor Author

jedelbo commented Apr 11, 2024

@tgoyne is anything blocking this now?

@tgoyne
Copy link
Member

tgoyne commented Apr 11, 2024

b56f162 eliminates the circular dependency that requires doing weird things with includes and extracts the easy-to-extract bits of duplicated logic.

@jedelbo
Copy link
Contributor Author

jedelbo commented Apr 12, 2024

@tgoyne Probably a better idea to collect all the templates in object_accessor.hpp - although they are collection accessors. I am not sure your changes works in all cases - I will have to make some more tests.

@jedelbo jedelbo force-pushed the je/nested-collection-accessor branch from d37888b to e71f412 Compare April 16, 2024 07:32
@jedelbo
Copy link
Contributor Author

jedelbo commented Apr 22, 2024

@tgoyne - your turn

{
return dispatch([&](auto t) {
return ctx.box(this->get<std::decay_t<decltype(*t)>>(row_ndx));
using U = std::decay_t<decltype(*t)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why this change here is causing a test to fail, in line 428 when the value is an object within an enumeration, with this error
realm::InvalidTableRef: null trying to call the Mixed constructor, I don't know why
Changing line 428 to return ctx.box(this->get<std::decay_t<decltype(*t)>>(ndx)); doesn't call the Mixed constructor and doesn't fails

if constexpr (std::is_same_v<U, Obj>) {
ObjKey old_key;
if (auto old_value = dict().try_get(key)) {
old_key = old_value->get_link().get_obj_key();
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a crash when trying to add a Realm Object into a dictionary of realm objects. This tries to read the mixed values from the dictionary when is actually a dictionary of objects, this crash when trying to get the type of the mixed.

@jedelbo jedelbo requested a review from dianaafanador3 April 24, 2024 08:56
Copy link
Contributor

@dianaafanador3 dianaafanador3 left a comment

Choose a reason for hiding this comment

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

LGTM!, Changes are working fine with CIM implementation

@jedelbo jedelbo merged commit b2e42c8 into master Apr 25, 2024
8 of 34 checks passed
@jedelbo jedelbo deleted the je/nested-collection-accessor branch April 25, 2024 08:24
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants