-
Notifications
You must be signed in to change notification settings - Fork 76
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
Validation errors handling #96
Comments
Doh. Nice find. What would you expect to happen in this case? Out of curiosity, what is the error that is preventing the save from taking place? Is it recoverable? Do you think that there needs to be some mechanism to try to prevent the failure, or should it just terminate here and cause the failureBlock to fire with the Core Data error code? Thanks,
|
Well, I think that there are two different issues to cover here: when there are Coredata saving issues I would expect the failure block to be invoked with the core data error object returned as a parameter. Validation errors should be treated differently: the saving that occurs at this point is not intended to persist data but to propagate the new records in the user's managed object context. I would expect validation errors to occur instead when the user try to persist data (i.e. calling [context save:] on his managedObjectContext). This is useful when data contained in the remote server is "dirty" and does not conform to the rules defined in the local model. I submit a PR that extends NSManagedObjectContext to make it skip validation: #97 I used associated objects as it was faster to implement, but a subclass could be used instead. What do you think? |
Isn't this a case where having MMRecord be a subclass of NSManagedObject is actually a good thing? You could just implement that method on your own record classes and control the logic however you like. That seems to me like the better way to handle this versus baking it into the library completely. The place where I'd love to see MMRecord improve is by really and truly implementing and playing nicely with this sort of validation as a first class citizen. I've thought about that before but never really come up with a good way to do it that makes sense. Part of it is because the Core Data validation seems a bit arbitrary to me and hasn't really ever even felt like something I wanted to use...so I was hesitant to base the MMRecord implementation solely off of that. I'm open to suggestions for how that might work though. |
As a user I can see two possible uses for validation: in the simple one, I want to let in my local data only records that conform to my validation rules and have an error returned in all the other cases. One possible way to support this scenario could be just failing on error while saving in The second scenario is the one described above: I have some "dirty" data on a remote server and I want the app's user to have the chance to correct data before committing it to the local persisting store. In this scenario, this method: |
hi again,
I noticed that when the background context can't be saved at the end of the marshaling process, i.e. for a validation issue, the request succeed and it returns an array of objectIDs anyway. Is it correct? The new data wasn't saved in the main context and the API just returns an array of the old values of the local persisted data.
Here is the code:
The text was updated successfully, but these errors were encountered: