Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RealmSwift 5.5.0 Unable to open 4.4.1 Realm file - ERROR: Key Already Used #6884

Closed
duncangroenewald opened this issue Oct 22, 2020 · 12 comments
Assignees

Comments

@duncangroenewald
Copy link

duncangroenewald commented Oct 22, 2020

Goals

Open RealmSwift 4.4.1 local file with RealmSwift 5.5.0.

Expected Results

When opening RealmSwift 4.4.1 files with RealmSwift 5.5.0 we expect the file to be upgraded and opened without any errors.

Actual Results

RealmSwift 5.5.0 reports a fatal error "Key Already Used" when trying to open a Realm 4.4.1 file.

Steps for others to Reproduce

Open the Realm 4.4.1 file with an app using the Swift 5.5.0 RealmSwift library.

Code Sample

Can provide the Realm 4.4.1 file to debug via private channel

Version of Realm and Tooling

Realm framework version: Original realm file is RealmSwift 4.4.1.
Upgrading to RealmSwift 5.5.0

Realm Object Server version: Realm Cloud (not sure of what version)

Xcode version: 12.1

iOS/OSX version: macOS 10.15.7

Dependency manager + version: N/A

@jsflax
Copy link
Contributor

jsflax commented Oct 23, 2020

Hi @duncangroenewald , could you provide us with a bit of sample code? Or at least a stack trace? Curious where this is occurring.

@duncangroenewald
Copy link
Author

@jsflax - sure I will take a look at it again and get back to you. I don't think there is a stack trace or I would have provided one.

@duncangroenewald
Copy link
Author

duncangroenewald commented Nov 12, 2020

@jsflax - is there any chance you guys can do a RealmSwift 4.4.1 build with XCode 12 ? We're still not confident enough to go to 5.5.0 in production yet. I might raise a new issue for this.

@duncangroenewald
Copy link
Author

duncangroenewald commented Nov 12, 2020

@jsflax - if I try and open the realm file with Realm Studio v3.11.0 I get the same error while upgrading the format - no crash. I can send you a dropbox link to the file via email if you provide an email address - it is around 40MB.

image

@tristangrichard
Copy link

Just downgraded back to 4.1.1. Still way more stable than 5+. Running xCode 12 with carthage

@duncangroenewald
Copy link
Author

Just downgraded back to 4.1.1. Still way more stable than 5+. Running xCode 12 with carthage

@trr-amsiq are you using this with Realm Cloud ? If so how did you get the sync component included ?

@tristangrichard
Copy link

@duncangroenewald sorry missed that part!
No I am not using Realm Cloud

@ericjordanmossman
Copy link
Contributor

@duncangroenewald

I can send you a dropbox link to the file via email if you provide an email address

Can you send to eric.mossman@mongodb.com?

@sync-by-unito sync-by-unito bot changed the title RealmSwift 5.5.0 Unable to open 4.4.1 Realm file - ERROR: Key Already Used RealmSwift 5.5.0 Unable to open 4.4.1 Realm file - ERROR: Key Already Used Jan 21, 2021
@ericjordanmossman
Copy link
Contributor

@duncangroenewald
Have you hit this at all when working with versions >10? Are you still seeing this in 5.5.0?

@duncangroenewald
Copy link
Author

@ericjordanmossman - as far as I am aware the issue still exists. However we are just working around this since it appears to be specific to a particular scenario, see the explanation from @ianpward below:

OK - so the issue here is:

In a core-5 file (RealmSwift 4.4.1), a table with a string primary key contains a column "!OID" that contains the "stable id" generated by object-store. This value is used as ObjKey when creating the objects in the core-6 file. For some reason, for the last two objects in the "LoginSession" table this value is 0. So when migrating the second object we get the "Key already used" exception. This is clearly an error in the input file as zero should never occur as !OID value. For this particular file you can just generate new keys for those objects, but it is hard to derive a general rule that would fix this problem.

I can try and reproduce this creation of records with OID = 0 with SDK 5.x and 10.x if someone can explain how we can check the value of OID on the records.

@jsflax
Copy link
Contributor

jsflax commented Aug 5, 2021

@duncangroenewald I know it's been a while, but– is this ticket still valid for you? I know you've been working on updated to 10.x.

@sync-by-unito sync-by-unito bot added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Aug 5, 2021
@sync-by-unito sync-by-unito bot assigned jsflax and unassigned ericjordanmossman Aug 5, 2021
@duncangroenewald
Copy link
Author

@jsflax

That bug was never fixed but we found a workaround so are currently using 5.x in production and testing 10.x on MongoDB Realm (cloud). I did see some others have posted what looked like the same bug.

I didn't close this because I presume that same bug is still lurking in core somewhere waiting for the right set of circumstances.

I will close this and if need be raise another if we ever see a reoccurrence on 10.x

@no-response no-response bot removed the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Aug 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants