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

chore: log a warning when DataStore is ignoring an attempted PK update #10756

Merged
merged 1 commit into from Dec 9, 2022

Conversation

svidgen
Copy link
Contributor

@svidgen svidgen commented Dec 9, 2022

Description of changes

DataStore does not update PK values on existing records. This behavior is by design, but has proven to be confusing when customers are not aware of it. This PR attempts to inform customers by logging a warning when a copyOf invocation attempts to update a PK field.

Warnings will look similar to this:

[WARN] 32:03.272 DataStore - copyOf() does not update PK fields. The 'id' update is being ignored. {
  source: Model {
    field1: 'something',
    dateCreated: '2022-12-09T16:32:03.272Z',
    id: 'b47c45a9-7ac4-405b-a07f-152fda83813c',
    _version: undefined,
    _lastChangedAt: undefined,
    _deleted: undefined
  }
}

We considered changes to this save() behavior to update the item, create a new item, or throw an error. But, these have been deemed breaking changes. This change will provide some guidance without breaking changes.

Issue #, if available

Description of how you validated changes

Added tests to spy on console warn calls.

Checklist

  • PR description included
  • yarn test passes
  • 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.

@svidgen svidgen requested a review from a team as a code owner December 9, 2022 16:41
@codecov-commenter
Copy link

Codecov Report

Merging #10756 (8eff711) into main (4725b5f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main   #10756   +/-   ##
=======================================
  Coverage   86.16%   86.16%           
=======================================
  Files         196      196           
  Lines       18351    18354    +3     
  Branches     3905     3906    +1     
=======================================
+ Hits        15812    15815    +3     
  Misses       2464     2464           
  Partials       75       75           
Impacted Files Coverage Δ
packages/datastore/src/datastore/datastore.ts 88.36% <100.00%> (+0.03%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@iartemiev iartemiev left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻

@svidgen svidgen merged commit cde60fc into aws-amplify:main Dec 9, 2022
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

4 participants