Open fkjohn opened 1 year ago
@fkjohn Thank you for reporting and providing a reproduction case.
I have experimented a bit by using node.js on MacOS, and I have created the following script (convert.js
):
const Realm = require("realm");
const appId = "gh5389-kjtot";
const crash = process.argv.length === 2;
const TaskSetting = {
name: "TaskSetting",
embedded: true,
properties: {
isActive: 'bool?',
},
};
const Task = {
name: "Task",
primaryKey: '_id',
properties: {
_id: {type: 'objectId', default: () => new Realm.BSON.ObjectId()},
description: 'string',
isComplete: {type: 'bool', default: false},
createdAt: {type: 'date', default: () => new Date()},
userId: 'string',
settings: 'TaskSetting',
},
};
const app = new Realm.App(appId);
app.logIn(Realm.Credentials.anonymous()).then(user => {
const configSync = {
path: "converted",
schema: [Task, TaskSetting],
sync: {
partitionValue: user.id,
user,
},
};
const configLocal = {
schema: [Task, TaskSetting],
};
console.log("Open Realm: ", JSON.stringify(configLocal));
Realm.open(configLocal).then(realm => {
console.log("Realm at ", realm.path);
console.log("Task 1");
realm.write(() => {
realm.create("Task", {
description: "Task 1",
userId: user.id,
settings: {
isActive: true,
},
});
});
if (crash) {
console.log("Task 2");
realm.write(() => {
realm.create("Task", {
description: "Task 2",
userId: user.id,
});
});
}
console.log("Convert to synced Realm");
realm.writeCopyTo(configSync);
console.log("Closing");
realm.close();
console.log("Closed!");
process.exit();
}).catch(err => console.log(err));
}).catch(err => console.log(err));
If I run node convert.js no-crash
I observe no errors. But while I run node convert.js
(and setting crash
to true), I get the following error Error: No object with key '4840227489' in 'class_TaskSetting'
.
We need to investigate it further.
@fkjohn I can repro it in core. We'll prepare a fix for it.
Was this fixed? We are getting the similar issue when fetching relationship of the object. realm: 12.12.1 react-native with Hermes enabled
How frequently does the bug occur?
Always
Description
I have an app which allows the user to choose if he wants to have an offline, non-synced or a synced realm. The goal is to offer the user to switch between both. The data model contains objects which have embedded objects as attribute. It is no problem the create objects where the embedded object is undefined, no matter if the user starts non-synced or synced. The attribute is also not set as mandatory, so this is the behavior I expect. However, when converting a non-synced realm to a synced realm with writeCopyTo the app crashes without meaningful error message. Converting a synced to a local realm is working without problem.
When investigating the issues it seems as if the error happens during the sync process to atlas. The realm file gets created correctly during writeCopyTo, and all data is existing in it. However, the data is not synced to the Atlas database. When creating new data after starting the app again, the new objects are synced to the Atlas database - however the ones that should be synced during migration are not.
Stacktrace & log output
Can you reproduce the bug?
Always
Reproduction Steps
I've created a repo to reproduce the bug based on the Expo Task Template: https://github.com/fkjohn/realm-crash
It works when setting {} as value of the embedded object:
When leaving the embedded object undefined, it crashes:
Version
11.3.1, also noticed with earlier versions of v10 and v11
What services are you using?
Atlas Device Sync
Are you using encryption?
No
Platform OS and version(s)
iOS
Build environment
Which debugger for React Native: ..
Cocoapods version
No response