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

Fix 476 #477

Merged
merged 8 commits into from
Feb 10, 2018
Merged

Fix 476 #477

merged 8 commits into from
Feb 10, 2018

Conversation

3lvis
Copy link
Owner

@3lvis 3lvis commented Feb 10, 2018

The bug is caused by the following line:

childPredicate = NSPredicate(format: "ANY %K IN %@ OR %K = %@", entity.sync_localPrimaryKey(), childIDsObject, inverseEntityName, self)

When creating the predicate Core Data expects that the array of elements in the IN closure to have the same type have as the ones inserted in Core Data. In this specific case, we have an array of Strings coming from the JSON and locally an array of Dates, this causes Core Data to crash when trying to execute the fetch request using the provided predicate since it expects an array of Dates from the JSON as well.

@3lvis
Copy link
Owner Author

3lvis commented Feb 10, 2018

I'm thinking this bug probably applies for many to many as well since the predicate is "ANY %K IN %@" but that could be solved in a separate PR.

if manyToMany {
childOperations.remove(.delete)
if ((childIDs as Any) as AnyObject).count > 0 {
guard let entity = NSEntityDescription.entity(forEntityName: childEntityName, in: context) else { fatalError() }
guard let childIDsObject = childIDs as? NSObject else { fatalError() }
childPredicate = NSPredicate(format: "ANY %K IN %@", entity.sync_localPrimaryKey(), childIDsObject)
}
} else {

@3lvis 3lvis changed the title Reproduce 476 Fix 476 Feb 10, 2018
@3lvis 3lvis merged commit 98c6c1f into master Feb 10, 2018
@3lvis 3lvis deleted the reproduce-476 branch February 10, 2018 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant