Skip to content

fix(datastore): prevent version cross-contamination between different model types#14570

Open
anivar wants to merge 2 commits intoaws-amplify:mainfrom
anivar:fix/datastore-save-version-conflict-13412
Open

fix(datastore): prevent version cross-contamination between different model types#14570
anivar wants to merge 2 commits intoaws-amplify:mainfrom
anivar:fix/datastore-save-version-conflict-13412

Conversation

@anivar
Copy link
Copy Markdown
Contributor

@anivar anivar commented Sep 26, 2025

Description of changes

Fixes issue where DataStore MutationEvent queries in the outbox matched by modelId only, without filtering by model type. This caused _version cross-contamination when different model types shared the same primary key value, leading to version conflict errors on subsequent mutations.

Three locations fixed in outbox.ts:

  1. enqueue() — existing mutation lookup now filters by model + modelId
  2. getForModel() — query now filters by model + modelId
  3. syncOutboxVersionsOnDequeue() — version sync query now filters by model + modelId

Test fixes:

  • Fixed getModelDefinition() calls in tests to pass the model constructor (Model) instead of a model instance, which returned undefined when the model filter was added
  • Fixed processMutationResponse() helper to pass constructor to getModelDefinition()
  • Added new test verifying _version isolation between different model types sharing the same ID

Issue #, if available

Resolves #13412

Description of how you validated changes

  • All 6 outbox tests pass
  • Full datastore test suite: 1159/1175 pass (2 failures are pre-existing flaky timeout in connectivityHandling.test.ts, unrelated to this change)

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

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

@anivar anivar requested a review from a team as a code owner September 26, 2025 18:31
@bobbor bobbor self-assigned this Dec 3, 2025
@anivar anivar force-pushed the fix/datastore-save-version-conflict-13412 branch from f9f463d to 26fe0cd Compare March 7, 2026 13:06
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 7, 2026

🦋 Changeset detected

Latest commit: 28d7ee0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-amplify/datastore Patch
aws-amplify Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

anivar added 2 commits March 7, 2026 18:59
… model types (aws-amplify#13412)

All MutationEvent queries in the outbox (enqueue, getForModel,
syncOutboxVersionsOnDequeue) now filter by both `model` and `modelId`
to prevent _version cross-contamination when different model types
share the same primary key value.

Added test verifying that dequeuing a mutation for one model type does
not update the _version on queued mutations for a different model type
with the same ID.
@anivar anivar force-pushed the fix/datastore-save-version-conflict-13412 branch from 26fe0cd to 28d7ee0 Compare March 7, 2026 13:36
@anivar
Copy link
Copy Markdown
Contributor Author

anivar commented Mar 7, 2026

This fix may help with sync issues reported in #14572 (DataStore not syncing backend changes) — version cross-contamination between different model types could cause silent sync failures.

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.

Datastore.save() sending _version of previous query model instead of current model.

2 participants