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(@aws-amplify/datastore-storage-adapter): SQLiteAdapter fails on required related models #10720

Merged
merged 11 commits into from Nov 29, 2022

Conversation

svidgen
Copy link
Contributor

@svidgen svidgen commented Nov 28, 2022

Description of changes

Adding manyToMany tests revealed that the SQLiteAdapter was failing to handle required related models correctly. As it was loading from the database, the adapter was attempting to initialize records with null values for the required related-model fields, rather than allowing these fields to be lazy-loaded using the given FK's. This was causing operations against models with required belongsTo and hasOne fields to throw errors, due to the fields being initialized null.

I'm not completely sure why these fields are present in the SQLite schema to begin with, so I'm leaving them in for now. However, this change fixes the issue by filtering related model fields out of the initialization entirely. Only the FK's should be populated.

Issue #, if available

#10718

Description of how you validated changes

Added unit tests. Red/Green'd the tests.

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.

Adding some hope-fully helpful comments.
@svidgen svidgen marked this pull request as ready for review November 28, 2022 23:04
@svidgen svidgen requested a review from a team as a code owner November 28, 2022 23:04
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 👍🏻

@codecov-commenter
Copy link

Codecov Report

Merging #10720 (6c2ed2d) into main (def0154) will increase coverage by 0.05%.
The diff coverage is 97.36%.

@@            Coverage Diff             @@
##             main   #10720      +/-   ##
==========================================
+ Coverage   85.65%   85.71%   +0.05%     
==========================================
  Files         196      196              
  Lines       18261    18335      +74     
  Branches     3892     3900       +8     
==========================================
+ Hits        15642    15715      +73     
- Misses       2543     2544       +1     
  Partials       76       76              
Impacted Files Coverage Δ
packages/datastore/__tests__/commonAdapterTests.ts 98.16% <97.26%> (-0.17%) ⬇️
packages/datastore/__tests__/helpers.ts 84.24% <100.00%> (+0.10%) ⬆️
packages/datastore/src/storage/relationship.ts 93.67% <0.00%> (+1.26%) ⬆️

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

@svidgen svidgen requested a review from dpilch November 29, 2022 03:52
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