DeepDiff icon indicating copy to clipboard operation
DeepDiff copied to clipboard

NSInternalInconsistencyException: reason: 'attempt to delete row 0 from section 0, but there are only 0 sections before the update'

Open rkittinger opened this issue 7 years ago • 8 comments

I am using ver.1.1.1 and the app crashes sometimes with:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 0 from section 0, but there are only 0 sections before the update'

Has this been fixed in 1.1.2? I saw here that it could take a while to fix: https://medium.com/flawless-app-stories/a-better-way-to-update-uicollectionview-data-in-swift-with-diff-framework-924db158db86

rkittinger avatar Feb 14 '18 09:02 rkittinger

@rkittinger I haven't seen this problem. Maybe your data has changed to 0 just before DeepDiff finishes ?

onmyway133 avatar Feb 14 '18 12:02 onmyway133

We seemed to have fixed the problem above, but crashes in this case:

          self.tableView.reload(changes: self.diffModels) { _ in
                    UIView.setAnimationsEnabled(true)
                    self.diffModels.removeAll()
                }

error: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (15) must be equal to the number of rows contained in that section before the update (15), plus or minus the number of rows inserted or deleted from that section (15 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

rkittinger avatar Feb 23 '18 13:02 rkittinger

@rkittinger I hit the issue you're describing. I've been using Differ in the past, but ran into the invalid update error and had to work around it. I thought it was an isolated case since I couldn't find any other issue describing the problem. Today I figured I'd give DeepDiff a try, to see if it had the same issue, and it does.

I've found an article that explains the issue, and the proposed fix/workaround also worked well for me: https://fangpenlin.com/posts/2016/04/29/uicollectionview-invalid-number-of-items-crash-issue/

I've personally only hit it for collection views, not table views. Perhaps the new API for performBatchUpdates on UITableView introduced in iOS 11 causes the same problem, and that is what you are seeing.

Burgestrand avatar Apr 04 '18 21:04 Burgestrand

@Burgestrand Hi, I will try to look into https://fangpenlin.com/posts/2016/04/29/uicollectionview-invalid-number-of-items-crash-issue/ soon. Do you have a test or demo that reproduces this bug?

onmyway133 avatar Apr 12 '18 07:04 onmyway133

A workaround is to check data source for number of objects before perform changes of diffing. This can be added to DeepDiff or users must do this before calling apply(changes) in client code

onmyway133 avatar Jun 15 '18 11:06 onmyway133

@onmyway133 I'm experiencing the same issue and would like to try to solve it. I suppose one could let the client call into DeepDiff to get value that the clients needs to return from function numberOfItemsInSection thus returning the appropriate values depending on the phase of any current batch operation (as proposed in the linked article above). Do you have any other ideas on how to implement the fix in DeepDiff?

snoozemoose avatar Jun 20 '18 09:06 snoozemoose

@rkittinger @snoozemoose @Burgestrand Hi, I just introduced updateData in this new release https://github.com/onmyway133/DeepDiff/releases/tag/1.4.0, hope it helps

onmyway133 avatar Jan 04 '19 12:01 onmyway133

When I remove, the number/ranking on the leaderboard does not update.

tccpg288 avatar Feb 14 '19 03:02 tccpg288