-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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(@aws-amplify/datastore): strictly define null vs undefined behavior on models #11009
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #11009 +/- ##
==========================================
- Coverage 82.21% 82.21% -0.01%
==========================================
Files 193 193
Lines 19296 19389 +93
Branches 4165 4192 +27
==========================================
+ Hits 15865 15940 +75
- Misses 3143 3161 +18
Partials 288 288
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides a super minor nit on a comment, LGTM! 🎉 As always, really appreciate the in-depth level of testing, as well as the informative comments.
Co-authored-by: David McAfee <mcafd@amazon.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Resubmitted
Originally submitted as #10915, which caused failing integ tests, due to
owner: null
being submitted in mutations when the theowner
field was made explicit. AppSync rejectsowner: null
as "Unauthorized."This updated PR omits the owner field in mutations (or custom owner field per model
attributes.auth
) when the value would benull
orundefined
.Added tests for
owner
handling are in connectivityHandling.test.ts:102-168, with owner field validation occurring in the graphql fake in helper.ts.The fix is for
owner
handling is inmutation.ts
on lines 487-490 and lines 526-529.You can also see the bulk of the
owner
field fix and tests together by looking at the 2nd commit in the PR.The 2nd attempt under #10932 revealed model instances failing validation during
copyOf
of models explicit timestamp fields. Timestamp fields are never actually required by AppSync, so it's safe from a runtime perspective to omit them even when marked as required in the MIPR. Even though this is a bug in runtime validation, it's an existing bug that we need to consider independently, especially as fixing the validation could actually be construed as a breaking change.To address this, this PR treats all timestamp fields as optional.
Description of changes
DataStore currently treats nullable model fields different before/after synchronization, which can lead to unexpected results when operating against or querying these instances. For example:
Given:
If we save an instance:
We'll have this returned:
If we query by ID before the instance is synchronized to the cloud, we see the same thing. And, if we query for models where
m.otherValue.eq(null)
, the model is not in the result set, because the field is actuallyundefined
.However, after synchronization, the the cloud storage provider (e.g., AppSync) will set optional fields to
null
:The model will then appear in the result set if we search for
m => m.otherValue.eq(null)
.This is an unintended behavior that customers should not have to work around. This PR normalizes that behavior so that optional fields default to
null
when unspecified or specified asundefined
. (undefined
can't actually be persisted in cloud storage.)Issue #, if available
Description of how you validated changes
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.