Skip to content

Commit

Permalink
Allow collections of non-embedded objects in asymmetric objects
Browse files Browse the repository at this point in the history
The schema validation checks forbidding this were removed in #6981, but Table
also had its own validation.
  • Loading branch information
tgoyne committed Sep 28, 2023
1 parent 8cc99bb commit be58eae
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 109 deletions.
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 @@ -165,51 +165,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

0 comments on commit be58eae

Please sign in to comment.