-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
Description
I'm testing the pre-release branch with our existing app. We had some code creating a bunch of nested items with UUID IDs for the primary keys in a loop which now throws an error but worked in 10.20.0 and earlier.
function loadThings(importModel: ImportModel[]) { realm.write(() => { for (const item of importModel) { const savedRealmThing = realm.create<RealmThing>(RealmThing.schema.name, createRealmThing(item)) const aliases = item.aliases ? item.aliases : [] const thingNames = [...aliases, item.name] thingNames.forEach((name) => { const alias = { id: uuid.v4(), thing: savedRealmThing, name: name, schema: latestRealmSchema.realmAlias, } realm.create<RealmAlias>(RealmAlias.schema.name, alias) }) } }) return importModel.length }
When it gets to realm.create<RealmAlias>(RealmAlias.schema.name, alias) it dies, apparently because it's trying to recreate the nested savedRealmThing and the object already exists. Changing that line to realm.create<RealmAlias>(RealmAlias.schema.name, alias, Realm.UpdateMode.Modified) fixes the issue.
It seems like the existing behaviour for realm.create() with no UpdateMode was Modified but is now Never, was this a deliberate change?
Stacktrace & log output
Error is: `Exception in HostFunction: Attempting to create an object of type 'RealmThing' with an existing primary key value ''0c5f1ca1-1e08-48a2-a75b-e5a302db67d5''.`
Can you reproduce a bug?
Yes, always
Reproduction Steps
See example code in description
Version
hermes (10.20.0-beta.1)
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
RN 0.66.3 using JSC (not Hermes!) - iPhone 13 Simulator w/ iOS 15.2, Android AVD Emulator running Android 9.0