-
Notifications
You must be signed in to change notification settings - Fork 154
feat(idempotency): leverage new dynamodB Failed conditional writes behavior #1779
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
Conversation
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
Hey @tolutheo , thank you for submitting your first PR to the project 🙏. Before we dive deeper into review, make sure to follow our contributor guide to link the issue and also describe your changes. In the meantime, I will take a look at the code so we can start the review. Thanks a lot! |
packages/idempotency/src/persistence/DynamoDBPersistenceLayer.ts
Outdated
Show resolved
Hide resolved
packages/idempotency/tests/unit/persistence/DynamoDbPersistenceLayer.test.ts
Outdated
Show resolved
Hide resolved
packages/idempotency/tests/unit/persistence/DynamoDbPersistenceLayer.test.ts
Outdated
Show resolved
Hide resolved
Kudos, SonarCloud Quality Gate passed!
|
f76ab6d
to
587da38
Compare
I've put the PR back into draft mode because the new implementation breaks the integration tests. I'll be working on verifying whether this is because the tests were too rigid or if indeed the implementation needs tweaking. |
I have refactored slightly the implementation and reverted most of the changes made in the unit tests. The current implementation follows this logic: When the Starting from this PR the write operation leverages a new-ish feature that allows the DynamoDB to return the item that caused the condition to fail. When an item is returned as part of the conditional write error, the Upper in the call stack, in the The change had to be made this way because the new feature is available only in newer AWS SDK versions (v3.363.0 or newer). This means that customers using older versions or any of the versions included in the Lambda managed runtimes (including the newer Node.js 20 one) won't be able to leverage this feature since older versions of the SDK don't include the item in the conditional write error. The integration tests are now passing as well: https://github.com/aws-powertools/powertools-lambda-typescript/actions/runs/7264829881/job/19793782219 |
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.
|
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.
Thanks for the PR and the work you both have put into that to simplify the implementation.
I was on the fence to add e2e tests, but this change is an implementation detail which would make the test brittle. The coverage with unit tests is sufficient.
I only added a small detail to the documentation.
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |
…havior (#1779) * created custom error with existingRecord field * fetch items in DB on ReturnValuesOnConditionCheckFailure * custom error field to fetch original Item from failed Item from Db * set base persitence layer to undefined. * converted error type to IdempotencyRecord * dev branch commit and unit tests * pull request corrections * chore: remove comment * chore: simplify conditional item hydration * chore: rebase * fix: use returned items + tests * add info about ReturnValuesOnConditionCheckFailure and conditional expression --------- Co-authored-by: Andrea Amorosi <[email protected]> Co-authored-by: Alexander Schueren <[email protected]>
Description of your changes
A couple of changes I am proposing to change in this feature request:
Implemented a custom error to contain existingRecord field here:
Error is then handled here using the code snippet below:
To make use of the existingRecord field, it is referenced here:
const idempotencyRecord: IdempotencyRecord = e.existingRecord;
So the getRecord API call is not made again to fetch item that lead to failure of the conditional write, the code snippet below is removed from here:
However the removal of that code causes a couple of unit tests listed below to fail with the error =>
The test expects getRecordSpy to be called once/twice/three times, but it is not called at all.
:To fix the issue we would need to remove the unit test
getRecordSpy
which is testing the getRecord code snippet mentioned above across those 4 unit test files.For now I haven't removed the getRecord because the test files were failing and wanted to inform you about them first. Other changes made to unit test file here:
Related issues, RFCs
Issue number: #1573
Checklist
Breaking change checklist
Is it a breaking change?: NO
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.