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

Allow collections of non-embedded objects in asymmetric objects #7003

Merged
merged 2 commits into from
Oct 2, 2023
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 @@ -2,7 +2,7 @@

### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* None.
* Allow collections of non-embedded links in asymmetric objects. ([PR #7003](https://github.com/realm/realm-core/pull/7003))

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
Expand Down
12 changes: 0 additions & 12 deletions src/realm/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,6 @@ ColKey Table::add_column_list(Table& target, StringData name)
Group* target_group = target.get_parent_group();
REALM_ASSERT_RELEASE(origin_group && target_group);
REALM_ASSERT_RELEASE(origin_group == target_group);
// Only links to embedded objects are allowed.
if (is_asymmetric() && !target.is_embedded()) {
throw IllegalOperation("List of objects not supported in asymmetric table");
}
// Incoming links from an asymmetric table are not allowed.
if (target.is_asymmetric()) {
throw IllegalOperation("List of ephemeral objects not supported");
Expand All @@ -486,10 +482,6 @@ ColKey Table::add_column_set(Table& target, StringData name)
REALM_ASSERT_RELEASE(origin_group == target_group);
if (target.is_embedded())
throw IllegalOperation("Set of embedded objects not supported");
// Outgoing links from an asymmetric table are not allowed.
if (is_asymmetric()) {
throw IllegalOperation("Set of objects not supported in asymmetric table");
}
// Incoming links from an asymmetric table are not allowed.
if (target.is_asymmetric()) {
throw IllegalOperation("Set of ephemeral objects not supported");
Expand Down Expand Up @@ -533,10 +525,6 @@ ColKey Table::add_column_dictionary(Table& target, StringData name, DataType key
Group* target_group = target.get_parent_group();
REALM_ASSERT_RELEASE(origin_group && target_group);
REALM_ASSERT_RELEASE(origin_group == target_group);
// Only links to embedded objects are allowed.
if (is_asymmetric() && !target.is_embedded()) {
throw IllegalOperation("Dictionary of objects not supported in asymmetric table");
}
// Incoming links from an asymmetric table are not allowed.
if (target.is_asymmetric()) {
throw IllegalOperation("Dictionary of ephemeral objects not supported");
Expand Down
63 changes: 20 additions & 43 deletions test/object-store/audit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,51 +167,28 @@ void sort_events(std::vector<AuditEvent>& events)
static std::vector<AuditEvent> get_audit_events_from_baas(TestAppSession& session, SyncUser& user,
size_t expected_count)
{
auto& app_session = session.app_session();
app::MongoClient remote_client = user.mongo_client("BackingDB");
app::MongoDatabase db = remote_client.db(app_session.config.mongo_dbname);
app::MongoCollection collection = db["AuditEvent"];
std::vector<AuditEvent> events;
static const std::set<std::string> nonmetadata_fields = {"activity", "event", "data", "realm_id"};

timed_wait_for(
[&] {
uint64_t count = 0;
collection.count({}, [&](uint64_t c, util::Optional<app::AppError> error) {
REQUIRE(!error);
count = c;
});
if (count < expected_count) {
millisleep(500); // slow down the number of retries
return false;
}
return true;
},
std::chrono::minutes(5));

collection.find({}, {},
[&](util::Optional<std::vector<bson::Bson>>&& result, util::Optional<app::AppError> error) {
REQUIRE(!error);
REQUIRE(result->size() >= expected_count);
events.reserve(result->size());
for (auto bson : *result) {
auto doc = static_cast<const bson::BsonDocument&>(bson).entries();
AuditEvent event;
event.activity = static_cast<std::string>(doc["activity"]);
event.timestamp = static_cast<Timestamp>(doc["timestamp"]);
if (auto it = doc.find("event"); it != doc.end() && it->second != bson::Bson()) {
event.event = static_cast<std::string>(it->second);
}
if (auto it = doc.find("data"); it != doc.end() && it->second != bson::Bson()) {
event.data = json::parse(static_cast<std::string>(it->second));
}
for (auto& [key, value] : doc) {
if (value.type() == bson::Bson::Type::String && !nonmetadata_fields.count(key))
event.metadata.insert({key, static_cast<std::string>(value)});
}
events.push_back(event);
}
});
auto documents = session.get_documents(user, "AuditEvent", expected_count);
std::vector<AuditEvent> events;
events.reserve(documents.size());
for (auto document : documents) {
auto doc = document.entries();
AuditEvent event;
event.activity = static_cast<std::string>(doc["activity"]);
event.timestamp = static_cast<Timestamp>(doc["timestamp"]);
if (auto it = doc.find("event"); it != doc.end() && it->second != bson::Bson()) {
event.event = static_cast<std::string>(it->second);
}
if (auto it = doc.find("data"); it != doc.end() && it->second != bson::Bson()) {
event.data = json::parse(static_cast<std::string>(it->second));
}
for (auto& [key, value] : doc) {
if (value.type() == bson::Bson::Type::String && !nonmetadata_fields.count(key))
event.metadata.insert({key, static_cast<std::string>(value)});
}
events.push_back(event);
}
sort_events(events);
return events;
}
Expand Down
2 changes: 1 addition & 1 deletion test/object-store/realm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3561,7 +3561,7 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") {
size_t schema_changed_called = 0;
Schema changed_fixed_schema;
TestFile config;
auto dynamic_config = config;
RealmConfig dynamic_config = config;

config.schema = Schema{{"object1",
{
Expand Down
Loading