-
Notifications
You must be signed in to change notification settings - Fork 236
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
Cache fails to update when updating an NSManagedObject for a value that was fetched form the database as Nil #118
Comments
Also I don't know if this is related, but I am getting another error that might be related when I use the original caching code. The error is an I've seen a couple of helps online: and http://www.cocoabuilder.com/archive/cocoa/292877-istemporaryid-unrecognized-selector-how-do-debug-this.html This 2nd thing makes me wonder if it is related to this cache issue and could be fixed with the same fix. I just don't understand the deal about inverse relations. Do you cache the inverse relation with the primary? I'm new to this caching stuff. Any insight would be great! |
UPDATE: I removed the caching code by commenting out
and the isTemporaryID goes away. |
Hi @tslater, thanks for finding this bug and a workaround. Did commenting out the caching section also fix the "you cannot start a transaction within a transaction" issue as well? Unfortunately the caching code wasn't written by myself so I'd need to do a bit more digging to fully understand the issue myself. I do wonder if a temporary fix might by to allow an option to turn off caching be set in "makeStoreWithOptions". |
I actually think I've got a solution. I'm still on my own hacked branch so it might take me a while to send up a PR because i still need to sort through it. There was even more work to do but I feel that the fix is ideal. I'll give you more details soon. |
@tslater, excellent. Really appreciate you keeping on top of it. I'll be on the lookout for a pull request and make sure to get it through quickly. |
After much debugging I too have found this bug. I have a really basic sample app if anyone needs something to test with.
does solve the issue but I'm not sure of the other consequences. I'm assuming that as nodeCache is a dictionary (containing dictionaries) it ignores the nil value when the object is first added to the cache and so doesn't contain the key relating to that value. Without a corresponding key the value cannot be updated in the cache and subsequent calls to the cache do not return a value. Navigating back down the navigation stack to a view controller where the database isn't accessed appears to clear the cache, and when it is recreated you see the updated value. That's my guess anyway. I'll have another look on Monday. |
The sample project is here.... https://github.com/sigmundfridge/encrypted-core-data-nil-cache/tree/master/TestMRImage It was a pretty quick project used to isolate the bug. You can add an Item using the plus sign. If you initially also add a photo then the imageUuid property of the Item is set and everything works as expected. If you save the Item without an image and then try to add an image you will see that the imageUUID is never set. However, if you navigate down to the start menu, and then go back to the list the Item will show the correct image. |
This is the line that ignores adding a value to the cached node unless it is not nil
|
In the documentation it says
so I believe this is being handled correctly when creating the node. However, for CMDIncrementalStoreNode
changedValues correctly passes the updated value (that was previously nil), but the method loops over self.allProperties, which does not contain the property to update. It may be better to loop over changedValues first, and then add any unchanged properties to the dictionary. |
I'm new to NSIncrementalNode so I'm a bit wary of making too many changes. However, this could work
However, it doesn't add the previously nil value to self.allProperties. |
OK. I'd be interested in any responses on this, but using the method above, and replacing
with
seems to be a fix. I'll send a PR. |
Ok. Not quite a fix.
Causes a 'cannot start a transaction within a transaction' error |
Ok. I'm back. So I have my own version of ECD that is now so far gone from what is in this repo that it is probably not possible to merge them together again ;-(. Anyway, I feel like my fixes below are super close. This fixes all of the caching behavioral problems and a reproducible crash with the aforementioned
|
The code as it stands does not have entityDescription. Other than that it all seems to work for me (but then I never found the 'unrecognized selector sent to instance' error. |
Hi @tslater and @sigmundfridge, Seems like you both have a good grasp of the issue, and are very close to a fix. Is there any piece of code I should merge in at the moment, or do you think there still needs to be some more work done? You're beyond where I can really help out too much, so let me know what I can do to support getting things resolved. As always, thanks for contributing and helping keep ECD working. |
I just keep putting off the inevitable--that I need to reconcile the public repo with what I have been doing. I have branched so far from this repo and made sooo many changes that I don't know if it's worth it anymore. If I figure out that I'm no longer going to try and merge with this repo I can try and clone down a fresh copy and make a PR with these changes. It will likely be a while though because my higher priority is to see if I can go back the current repo and merge this fix among many others...or if the current repo has some of my fixes already in it. I would do this as part of my reconciliation if it can be saved! |
Also @sigmundfridge sorry about the entityDescription thing...again my code has diverged a lot... |
I'll put those changes into a fresh repo and do a PR. Sent from my iPad
|
What happens is that allProperties on the CMDIncrementalStoreNode is set to only those properties that have values after a fetch because of these lines:
We tried changing them to be:
but then we got an error saying something like "you cannot start a transaction within a transaction"
The text was updated successfully, but these errors were encountered: