-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Crashes after making property optional #3732
Comments
Hey Bernhard, sorry that I didn't got back to you earlier, missed that you filed an issue over here.
That's true. How was it crashing for you? How were you testing the migration? Coming to the problem you're seeing with the deployed version: Did you added So if you still know or can figure out with which version, you introduced that property, then you can just make sure that this migration enumerations only objects of schemas which have this property already. if (5...13).contains(oldSchemaVersion) {
migration.enumerate(Post.className()) { oldObject, newObject in
if let oldDateSaved = oldObject?["dateSaved"] as? NSDate {
newObject?["dateSaved"] = oldDateSaved.timeIntervalSince1970 > 0 ? oldDateSaved : nil
}
}
} Alternatively you can dynamically check the if oldSchemaVersion < 13 {
migration.enumerate(Post.className()) { oldObject, newObject in
guard let _ = oldObject?.objectSchema["dateSaved"] else {
newObject?["dateSaved"] = nil
return
}
if let oldDateSaved = oldObject?["dateSaved"] as? NSDate {
newObject?["dateSaved"] = oldDateSaved.timeIntervalSince1970 > 0 ? oldDateSaved : nil
}
}
} |
We test migration with running the tests of our api communication framwork with the old version on the simulator and then run the tests for new new version. dateSaved was added more then 1,5 years ago and we also have a migration when we introduced it (never had problems so far)
We do not see any crashes right now but it looks like we are stuck in migration somewhere. |
Could you elaborate what you mean by the latter part?
There is Could you reproduce any of the errors you describe locally? If so, you're more than welcome to share more info. |
@BObereder hi, just following up on @mrackwitz's last comment. We'd love to help. |
Closing since we haven't heard back from @BObereder in a while. |
Goals
Hi,
we wanted to make a property optional and are experiencing some crashes.
We had a NSDate property non optional for a long time like this:
public dynamic var dateSaved: NSDate = NSDate(timeIntervalSince1970: 0)
and now we made it optional like this:
public dynamic var dateSaved: NSDate?
Usually this should work without any problems, just bump the schemaVersion and add an empty migration block.
Here was the first hurdle we had to add a migration since it was crashing. So we added the following migration.
Code Sample
Everything seemed fine. Migration worked.
Actual Results
Now in the release we have some crashes that we can not reproduce.
It crashes on this line:
if let oldDateSaved = oldObject?["dateSaved"] as? NSDate {
With this error:
Fatal Exception: RLMException
Invalid property name
dateSaved
for classPost
.Stack Trace
Version of Realm and Tooling
Realm version: v1.0.0
Xcode version: 7.3.1
Dependency manager: carthage
The text was updated successfully, but these errors were encountered: