-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
How frequently does the bug occur?
Always
Description
Trying to create objects in a new schema from the data in an old deleted schema.
onMigration: (oldRealm, newRealm) => { const oldObjects = oldRealm.objects(RealmSchema.OldSchemaName); oldObjects.forEach((obj) => { if (obj.arrayValue.length) { obj.arrayValue.forEach((arrItem) => { newRealm.write(() => { newRealm.create(RealmSchema.NewSchemaName, { key: oldObject.value, ..., ... }); }); }); } }); },
When I call `newRealm.write(() => {
newRealm.create(RealmSchema.NewSchemaName,
, Realm.UpdateMode.All) }){{ it always throws }}Error: Exception in HostFunction: The Realm is already in a write transaction`
Assigning values to the new object is not a problem since it doesn't require a write operation but creating a new object from an old one seems like a problem. I think I'm missing something here. Please let me know if there's a workaround.
The references doesn't show how to create a new object from old deleted objects.
Stacktrace & log output
Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
Possible Unhandled Promise Rejection (id: 0): Error: Exception in HostFunction: The Realm is already in a write transaction
Can you reproduce the bug?
Always
Reproduction Steps
- upgrade schema and version
- Realm fails to initialize when the onMigration callback runs at newRealm.write()
Version
11.10.2
What services are you using?
Local Database only
Are you using encryption?
Yes
Platform OS and version(s)
iOS/Android
Build environment
Which debugger for React Native: Flipper
Cocoapods version
No response