Skip to content

fix(idempotency): validate idempotency record returned in conditional write #2083

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
merged 5 commits into from
Feb 19, 2024

Conversation

dreamorosi
Copy link
Contributor

Description of your changes

This PR fixes a bug that was introduced in the last release and that caused the Idempotency utility to skip the validation of a payload on subsequent requests.

In order to leverage the new capability of ConditionalCheckFailedException to return the item that made the conditional check to fail, we had to implement a logic that sort of looks like this:

flowchart LR
    A[saveRecord] -->|ConditionalWrite| B{is new SDK}
    B -->|Yes| C[throw IdempotencyItemAlreadyExistsError with IdempotencyRecord]
    B -->|No| D[throw IdempotencyItemAlreadyExistsError  only]
Loading

The pseudo-saveRecord from the chart above is called by the IdempotencyHandler, which handled it this way:

flowchart LR
    A[catch IdempotencyItemAlreadyExistsError] --> B{does it have IdempotencyRecord?}
    B -->|Yes| C[use it as is]
    C --> H[carry on]
    B -->|No| E[read record from DDB]
    E --> F[validate current request vs stored record]
    F --> G{do they match}
    G -->|Yes| H
    G -->|No| I[throw IdempotencyValidationError]
Loading

As you can see from the flow above, in one of the paths the payload was never validated.

This PR changes the access property of the validatePayload method from private to public so that it's exposed on the persistence layer and can be called directly by the IdempotencyHandler.

The flow now looks like this:

flowchart LR
    A[catch IdempotencyItemAlreadyExistsError] --> B{does it have IdempotencyRecord?}
    B -->|Yes| C[validate payload]
    C --> G
    B -->|No| E[read record from DDB]
    E --> F[validate current request vs stored record]
    F --> G{do they match}
    G -->|Yes| H[carry on]
    G -->|No| I[throw IdempotencyValidationError]
Loading

Related issues, RFCs

Issue number: #2058

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

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.

@dreamorosi dreamorosi self-assigned this Feb 16, 2024
@dreamorosi dreamorosi requested a review from a team February 16, 2024 17:28
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Feb 16, 2024
@boring-cyborg boring-cyborg bot added idempotency This item relates to the Idempotency Utility tests PRs that add or change tests labels Feb 16, 2024
@github-actions github-actions bot added the bug Something isn't working label Feb 16, 2024
@dreamorosi
Copy link
Contributor Author

dreamorosi commented Feb 16, 2024

Adding this for visibility: aws-powertools/powertools-lambda-python#3781

@dreamorosi dreamorosi linked an issue Feb 16, 2024 that may be closed by this pull request
Copy link
Contributor

@kevin-secrist kevin-secrist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this bugfix so quickly! I left a comment on some logic that may be good to include here as well, or potentially as a separate PR.

Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suuuperb!

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

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

See analysis details on SonarCloud

@dreamorosi dreamorosi merged commit 037e71f into main Feb 19, 2024
@dreamorosi dreamorosi deleted the fix/idempotency_validation branch February 19, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working idempotency This item relates to the Idempotency Utility size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Payload validation broken for DynamoDBPersistenceLayer
4 participants