3Squared / SQKDataKit

Lightweight Core Data helper to reduce boilerplate code.
MIT License
19 stars 6 forks source link

Performing sqk_insertOrUpdate with data with duplicate keys results in duplicated managed objects #54

Closed blork closed 9 years ago

blork commented 9 years ago

If you try and insert data with duplicates like this:

NSArray *dictArray = @[
    @{ @"remote-sha" : @"123" },
    @{ @"remote-sha" : @"123" },
    @{ @"remote-sha" : @"123" }
];

Then you will end up with multiple managed objects inserted with the same ID. While this makes sense given the data, it is pretty definitely not what you want, since it's meant to be a unique key.

I have created a fix for this (cdbade916f1856b0fff4be31dde888a507e76cb9), but am not certain if the logic truly belongs in SQKDataKit or should uniqueness of the remote data be the caller's problem?

blork commented 9 years ago

@3squared/developers Anyone have any thoughts on whether this should be added?

lukestringer90 commented 9 years ago

I agree the API shouldn't necessary be sanitising data or performing any sort of logic of that sort. However can we think of a scenario where inserting duplicates would be desirable? I think it is more likely for the error case to be the norm.

So on balance, for convenience and to stop nasty, hard to narrow down bugs like this occurring again, we should include your fix in (cdbade916f1856b0fff4be31dde888a507e76cb9).