Skip to content

Bug: Treat missing idempotency key as non-idempotent transaction #2465

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

Closed
heitorlessa opened this issue Jun 15, 2023 · 4 comments · Fixed by #2477
Closed

Bug: Treat missing idempotency key as non-idempotent transaction #2465

heitorlessa opened this issue Jun 15, 2023 · 4 comments · Fixed by #2477
Assignees
Labels
bug Something isn't working idempotency Idempotency utility

Comments

@heitorlessa
Copy link
Contributor

heitorlessa commented Jun 15, 2023

Expected Behaviour

By default, treat a transaction that is missing idempotency key as a NO-OP transaction. That means, we will continue to log a warning and will not save at the configured persistence storage layer.

This prevents mistakes when an application is designed to optionally send an unique value (e.g., X-Idempotency-Value) and NULL doesn't get a unique sentinel value (e.g., UUID) in its absence.

Current Behaviour

By default, raise_on_no_idempotency_key is set to False. This means we will log a warning when the idempotency key is missing, since we don't know if that's intentional or not. However we continue treating the transaction like we normally would, hash the None value, and save it in the persistence store.

Tests confirming behaviour

Code snippet

from aws_lambda_powertools.utilities.idempotency import (
    DynamoDBPersistenceLayer, idempotent
)

persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
config = IdempotencyConfig(
    event_key_jmespath="headers.X-Idempotency-Value",  # Browser Might Not Send It
)

@idempotent(persistence_store=persistence_layer)
def handler(event, context):
    return {
        "message": "FIRST REQUEST",
        "statusCode": 200,
    }

Possible Solution

aws-powertools/powertools-lambda-typescript#1501

Steps to Reproduce

Calling the handler twice without the X-Idempotency-Value HTTP Header will return the first response in both requests.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

Lambda Layers

Debugging logs

No response

@heitorlessa heitorlessa added bug Something isn't working triage Pending triage from maintainers labels Jun 15, 2023
@heitorlessa
Copy link
Contributor Author

Originally discussed in TypeScript repo: aws-powertools/powertools-lambda-typescript#1501

@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Jun 15, 2023
@rubenfonseca
Copy link
Contributor

Looking at this now.

@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jun 16, 2023
@github-actions
Copy link
Contributor

This is now released under 2.17.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jun 16, 2023
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 Idempotency utility
Projects
None yet
2 participants