realm-swift: Crash "Key already used" after upgrading RealmSwift 3.21.0 --> 5.5.1
Goals
Save new object with Int primary key after upgrading RealmSwift 3.21.0 --> 5.5.1
Expected Results
Object created in Realm
Actual Results
Crash with “Key already used” message on adding new object
2021-05-10 15:09:13.622839+0300 realm-test[12261:2913798] *** Terminating app due to uncaught exception 'RLMException', reason: 'Key already used'
*** First throw call stack:
(0x1bfe65654 0x1bfb87bcc 0x105009ca8 0x104bc94e8 0x1049509d4 0x10494fe70 0x1049508dc 0x104950938 0x104bc86a8 0x104950820 0x10494fda0 0x10494fccc 0x10494d960 0x10494daac 0x1c3f0fc14 0x1c3f119a0 0x1c3f1723c 0x1c36bba68 0x1c3f13280 0x1c3f135d4 0x1c3f193e4 0x1f6a602b4 0x10494e310 0x10494e288 0x10494e354 0x1bfc658f0)
libc++abi.dylib: terminating with uncaught exception of type NSException
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'RLMException', reason: 'Key already used'
Steps for others to Reproduce
Create at least one object in Realm for Entity, which primaryKey is Int at RealmSwift 3.21.0 Upgrade RealmSwift to 5.5.1 Try to create new object with new id
Code Sample
https://github.com/Ogerets/realm-test/tree/develop-v3.21.0 https://github.com/Ogerets/realm-test/tree/develop-v5.5.1
Version of Realm and Tooling
Realm framework version: 3.21.0 --> 5.5.1
Xcode version: 12.4
iOS/OSX version: 13.7
Dependency manager + version: Cocoapods 1.10.1
Extra Info
- Trying to create new object in RealmStudio 5.0.0 also fails with same error “Key already used”, despite there’s no object with such key. Here is realm file after upgrade on which it can be reproduced.
- Upgrading 3.21.0 --> 5.5.0 works fine.
- For Entities with String primary key no problem occurs.
- Downgrade to 5.5.0 after 5.5.1 does not help.
- Upgrading from versions >3.21.0 to 5.5.1 seems to be okay.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 17 (1 by maintainers)
@Ogerets We now create a backup of the realm file when you upgrade major versions - so we are now giving you the capability to rollback if you are seeing serious regressions https://github.com/realm/realm-cocoa/blob/master/CHANGELOG.md#enhancements-2