Skip to content

fix(idempotency): validate before saving to cache #3822

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

Merged

Conversation

heitorlessa
Copy link
Contributor

@heitorlessa heitorlessa commented Feb 21, 2024

Issue number: #3821

Summary

As recently fixed in TS, we should be validating (payload tampering) before saving to cache.

Changes

Please provide a summary of what's being changed

  • Change order
  • Investigate redis tests failure
  • Add missing test to prevent future regression

Unrelated changes

  • Fix multi-processing serialization on race condition Redis test
    • Add multiprocess dev dependency to use dill over pickle for multi-process serialization

User experience

Please share what the user experience looks like before and after this change

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@heitorlessa heitorlessa requested a review from a team February 21, 2024 10:04
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 21, 2024
rubenfonseca
rubenfonseca previously approved these changes Feb 21, 2024
@heitorlessa heitorlessa marked this pull request as draft February 21, 2024 10:05
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e14e768) 96.38% compared to head (57f7f5e) 96.42%.
Report is 76 commits behind head on develop.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3822      +/-   ##
===========================================
+ Coverage    96.38%   96.42%   +0.04%     
===========================================
  Files          214      214              
  Lines        10030    10093      +63     
  Branches      1846     1866      +20     
===========================================
+ Hits          9667     9732      +65     
+ Misses         259      258       -1     
+ Partials       104      103       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@heitorlessa heitorlessa marked this pull request as ready for review February 21, 2024 10:12
@boring-cyborg boring-cyborg bot added dependencies Pull requests that update a dependency file tests labels Feb 21, 2024
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 21, 2024
@heitorlessa heitorlessa requested a review from sthulb February 21, 2024 10:27
@heitorlessa
Copy link
Contributor Author

@roger-zhangg and @leandrodamascena unrelated to this PR, Redis race condition tests were failing due to serialization in multi-processing -- only on M1, but not on CI.

Diving into this I found that the issue is due to the standard library multiprocessing using pickle for serializing functions to run (the target!). Because you're using a local function (closure) to run an idempotent function in a multiprocessing scenario (you're rightly so), pickle fails to serialize randomly.

To fix it, I've added multiprocess library. Two quick notes for you:

  1. Use from multiprocess instead of from multiprocessing (ING) to avoid this issue
  2. Please spend a bit more time annotating tests with GIVEN/WHEN/THEN to make it easier to grasp later. This is a complex test and it was difficult to track it down what it was doing and later the cryptic error
image

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
2.1% Duplication on New Code

See analysis details on SonarCloud

@heitorlessa heitorlessa changed the title refactor(idempotency): validate before saving to cache fix(idempotency): validate before saving to cache Feb 21, 2024
@github-actions github-actions bot added bug Something isn't working and removed enhancement labels Feb 21, 2024
@sthulb sthulb merged commit 812ab3f into aws-powertools:develop Feb 21, 2024
@heitorlessa heitorlessa deleted the fix/idempotency-validation-order branch February 21, 2024 10:57
@roger-zhangg
Copy link
Member

Thanks @heitorlessa , for the finding and fix. I wasn't aware of this M1 behavior difference before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: idempotency logic should first validate the payload and then cache
5 participants