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

[minor issue] Realm Core throws due schema mismatch, even if deleteRealmIfMigrationNeeded is set to true #3577

Closed
icanzilb opened this issue May 13, 2016 · 6 comments
Labels

Comments

@icanzilb
Copy link
Contributor

icanzilb commented May 13, 2016

Goals

Release 0.102.0 includes the following enhancement "Add deleteRealmIfMigrationNeeded to RLMRealmConfiguration/Realm.Configuration. When this is set to true, the Realm file will be automatically deleted and recreated when there is a schema mismatch rather than migrated to the new schema."

Discussion: This is a relatively minor problem because the exception is swallowed at RLMRealm.mm:406 but I'm just wondering if this feature is supposed to be available across threads shouldn't deleteRealmIfMigrationNeeded be handled at core level instead of throwing and handling this in the C++ library? E.g. if this is an intended behavior should the core use exceptions to talk to the bindings to implement logic?

Expected Results

I expect when I have a schema mismatch calling "Realm()" to simply delete the old file and keep on.

Actual Results

Realm() throws an exception about schema mismatch

Steps to Reproduce

code below

Code Sample

Here's the code to reproduce (provided you have a schema mismatch):

var config = Realm.Configuration()
config.deleteRealmIfMigrationNeeded = true
Realm.Configuration.defaultConfiguration = config
let realm = try! Realm()

Version of Realm and Tooling

Realm version: via CocoaPods

Using Realm (0.102.0)
Using RealmSwift (0.102.0)

Xcode version: Version 7.3.1 (7D1014)

iOS/OSX version: Version 9.3 (SimulatorApp-645.9

Dependency manager + version: CocoaPods 1.0.0 (release)

@bdash
Copy link
Contributor

bdash commented May 14, 2016

Is the issue you're raising the fact that an exception is used internally to communicate the schema mismatch? If so, why do you feel that is an issue?

@icanzilb
Copy link
Contributor Author

Yes, I'm just wondering why an exception is used for something that works just fine. I've been told a number of times using error handling mechanisms to implement logic was wrong (and I feel that way myself too)

@jpsim
Copy link
Contributor

jpsim commented May 16, 2016

A case could be made to avoid using exceptions for our implementation control flow, but this is an entirely internal codebase consideration, and something with very minimal impact given that we'll need to continue compiling our ObjC++ files with ARC's exception handling overhead for the large amount of core exception to NSError conversion.

As far as I can recall, the only place we do this is for this feature, which should be fully ported to the object store in the near future anyway, avoiding the need to throw & catch that exception.

For these reasons, I'm closing this issue.

@jpsim jpsim closed this as completed May 16, 2016
@shanemileham
Copy link

I believe I have the same issue, and I am unclear from reading the above comments how to fix it. I have a schema mismatch, and I would like Realm to delete on migration. My code is essentially the same as above:

[RLMRealmConfiguration defaultConfiguration].deleteRealmIfMigrationNeeded = YES;
RLMRealm *realm = [RLMRealm defaultRealm];

And this crashes my app on the second line (or during first Realm access if I omit that line) with the following error:

Terminating app due to uncaught exception 'RLMException', reason: 'Migration is required due to the following errors: ...

Do I just catch it and assume everything is okay? Or do I need to do something else in my code?

I've searched the Realm overview, docs, and google, and I don't know how to fix this, so
How do I fix this to avoid crashing my app? Thank you.

@tgoyne
Copy link
Member

tgoyne commented Sep 21, 2016

Your problem is entirely unrelated to this issue. [RLMRealmConfiguration defaultConfiguration].deleteRealmIfMigrationNeeded = YES; does not do anything because you're mutating a newly created object and then discarding it. You must set deleteRealmIfMigrationNeeded on a configuration object and then pass that object to [RLMRealmConfiguration setDefaultConfiguration:].

@shanemileham
Copy link

Ahhhhhh that makes a lot more sense. I missed that finer point. Thank you :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants