Skip to content
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

fix(datastore): Update mutations to filter out extra fields on clientside conflict resolution retry #12815

Closed
wants to merge 4 commits into from

Conversation

stocaaro
Copy link
Contributor

@stocaaro stocaaro commented Jan 8, 2024

Description of changes

Problem:
When Optimistic Concurrency resolution returns failures (when the posted version is different than the remote version), these failures are retried, updating to the remove version from the failure.

When this happens, new DataStore instances are created. The original objects may not contain all fields and missing fields are created on the new object with null content. The retry then saves these null values overwriting.

Solution:
After conflict resolution has happened, filter the resulting object down to only the fields from the original update.

This solution stops the overwriting of data with nulls and doesn't change any of the existing interfaces in potentially breaking ways.

Other solutions considered:

  • Send complete objects for conflict resolution - Which would be a breaking change into the conflict resolution API and would always send all fields for retried updates, which may introduce other sequential update issues.
  • Take the full remote object from the error and overwrite the updated fields - This would also be breaking and would send full data on update retries.

Issue #, if available

Description of how you validated changes

  • Validate by updating tests
  • Validated by testing against a linked sample app

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@stocaaro stocaaro requested a review from a team as a code owner January 8, 2024 23:04
Comment on lines +684 to +685
// @ts-ignore - This operation isn't supported in ts-strict, but needed to clone the needed fields across
returnObject[sKey] = inputObject[sKey];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the best way I found to enable this behavior. Very open to alternatives that achieve the same guarantees of honoring custom error handeling and while also not passing along more fields than the original request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talking with @svidgen there may be a way to leverage copyOf here that is worth investigating. I'm fuzzy on how we would do this without introducing a breaking change.

@stocaaro
Copy link
Contributor Author

This would have breaking side effects on how custom conflict resolution behaves. With this input I am closing this review.

@stocaaro stocaaro closed this Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant