mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
FetchExisting doesn't preserve subclass type #160
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sidmani on GitHub (Aug 16, 2017).
There's a limitation in fetchExisting at the moment- all subclass type information is lost when applying fetchExisting on a variable with a superclass type. Check out this code:
newBar now not only has type Foo, but is actually a Foo, and not just a Bar stored in a variable with type Foo. IMO, this is rather dangerous because it's required to call fetchExisting when entering and exiting transactions, and using variables with a superclass type is a common pattern if there are multiple subclasses. This issue silently stops subclass overrides of methods from being called- I didn't even notice until my unit tests caught it.
I'm going to play around with the code and see what I can come up with. Would appreciate your input @JohnEstropia (and I'm willing to author a pull request if you agree that this needs fixing).
edit: deleted irrelevant attempt at solving problem
@sidmani commented on GitHub (Aug 16, 2017):
Looking through the code, it seems that this behavior could even be inconsistent between invocations of the method- code from fetchExisting (NSManagedObjectContext+Querying.swift)
Unless I'm missing something basic, it seems like modifying this method is the way to go.
@JohnEstropia commented on GitHub (Aug 16, 2017):
Ah, good catch. Thanks!
@JohnEstropia commented on GitHub (Aug 16, 2017):
Merged the PR to the Swift 4 branch. Will cherry-pick into develop and Swift3.2 branches as well.