-
Notifications
You must be signed in to change notification settings - Fork 117
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
Datastore cannot sync new mutations after getting Failed to publish a local change error #1865
Comments
yeah the mutation processor basically hangs if an error occurs. #1845 should fix it one way or another. |
Because of primary key constraints Datastore cannot save the mutation and
|
Ouch yeah that's no good as well. I guess the PR I mentioned would only unlock the mutation engine to fail a again. So error is, mutation rapidly or just offline for user1. Mutation gets pushed. User2 gets mutation transition only and encounters error. Seems like the fix would be for rapid or unpublished mutations for the mutation engine on user1 to ensure it's somehow marked as a creation vs mutation bc otherwise user2 is going to get locked with that error of it not finding the metadata for the "existing" item |
The primary key constraint is an unrecoverable error. So I think mutation should be removed from the queue. Also send an Amplify.Hub message about the error. |
Woops yes the trace indicates it is in the drainMutationOutbox which is outbound. Did you save the first model to the datastore prior to mutating it? The model id shouldn't have changed. If not, ensure you save the model before doing a copy of operation to mutate it. If you had saved the model, this sounds buggy. It could be a bug where the first mutation hadn't even been processed for the storage engine, the mutation outbox merged the two models and then deeper down when it tried to find the model id as a mutation instead of really being a merged creation it would throw the error |
Hmm I see that you are using Key1 as the primary key, which you stated. But why not use ID! as the primary key? the uuids have a much better chance of no conflict. If you need special logic to ensure Key1 and Key2 must be unique on all models then you'd need a custom conflict resolution on the backend |
Regardless of the intention, the error messages seem to indicate what I stated previously as the id it's working on to merge the model is |
Seems related to #869 (comment) |
Because Amplify doesn't have any option for unique constraints. So I'm using composite primary constraints. Other database systems throw an exception because of primary key constraints. But Amplify doesn't do anything on the error, that's the problem I think. |
@shantanu-saha-europcar apologies for the delay here, the team is currently working on supporting custom primary keys and composite keys in DataStore. Once that feature is released, we will follow up with an update here and ask if this issue is then resolved for you. Thank you for your patience! |
@shantanu-saha-europcar we have identified the root cause and working on resolution. we will update once we resolve the issue. |
@AnilMaktala It will be helpful if you can explain the cause here. Thanks |
The cause of this issue is as explained in my earlier comment. The use of the |
|
Before opening, please confirm:
Language and Async Model
Kotlin
Amplify Categories
DataStore
Gradle script dependencies
Environment information
Please include any relevant guides or documentation you're referencing
No response
Describe the bug
I have the following model (dummy) with two keys as a primary key.
If two users use the app in offline mode and each user creates a row of ExampleModel with the same key1 and key2 value then after online 2nd user will get a mutation exception. It's because 1st user already submit the data to Amplify and 2nd user got a conflict (primary key constraints)
The problem is that after the exception user2 cannot publish other changes (also other models) to Amplify. Every change got enqueued but never submitted to Amplify. Also, the conflict handlers never trigger. I have tested the conflict handler for both conflict strategies. The only way to fix the issue is to uninstall the app.
Reproduction steps (if applicable)
No response
Code Snippet
// Put your code below this line.
Log output
amplifyconfiguration.json
No response
GraphQL Schema
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: