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): Fix beginsWith() negation #10962

Merged
merged 6 commits into from
Feb 10, 2023

Conversation

svidgen
Copy link
Contributor

@svidgen svidgen commented Feb 9, 2023

Description of changes

Fixes an issue where the absence of special handling for the negation of beginsWith resulted in an error for queries like this:

await DataStore.query(Model, m => m.not(m => m.field.beginsWith('anything')));

This fix would be a reasonable amount more difficult to figure out and grok using the existing storage predicate builder that V5 predicates was still using in some places. So, this PR pulls forward a refactor from #10949 around storage predication generation to make the fix sane and simple.

A component of that refactor is a fix to IndexedDBAdapter's determination of whether a predicate is a "key value predicate". I'm not sure clear on where the storage predicate builder handles null conditions, but IndexedDB throws a fit if you try to index.get([null]). For this refactor, I've opted explicitly handle this on the IndexedDBAdapter side, because issue only seems to affect IndexedDB.

Issue #, if available

#10957

Description of how you validated changes

  1. Added negation tests for each of our string matches.
  2. Saw the beginsWith negation test fail.
  3. Made it pass.

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 February 9, 2023 21:16
@codecov-commenter
Copy link

codecov-commenter commented Feb 9, 2023

Codecov Report

Merging #10962 (a20f80a) into main (7da8e64) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

📣 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   #10962      +/-   ##
==========================================
- Coverage   81.59%   81.55%   -0.04%     
==========================================
  Files         198      198              
  Lines       19609    19610       +1     
  Branches     4232     4237       +5     
==========================================
- Hits        15999    15993       -6     
- Misses       3319     3327       +8     
+ Partials      291      290       -1     
Impacted Files Coverage Δ
packages/datastore/src/predicates/next.ts 94.94% <100.00%> (+0.30%) ⬆️
.../datastore/src/storage/adapter/IndexedDBAdapter.ts 89.07% <100.00%> (+0.11%) ⬆️
packages/datastore/src/predicates/index.ts 78.86% <0.00%> (-9.76%) ⬇️
packages/datastore/src/util.ts 95.90% <0.00%> (+0.86%) ⬆️

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

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