Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GET

Ouverte Adaptée aux débutants
#8,727 4 commentaires 0 réactions 1 personne assignée Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@coughlmao y travaille déjà.

Depuis le 1/11/2026.

  • #8736 par @coughlmao — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
85/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python, redis
Domaine
databases

Piste de recherche

Modifiez aws_lambda_powertools/utilities/idempotency/persistence/redis.py dans _put_record : capturez IdempotencyItemNotFoundError après l'échec de SET NX et levez IdempotencyInconsistentStateError. Ajoutez un test avec un client fictif renvoyant None sur GET, en affirmant que la fonction décorée s'exécute. Terminé lorsque ce test passe et que le snippet dans l'issue renvoie "ok".

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug good first issue help wanted idempotency

[!WARNING]
For contributors, human or agent. Comment here to claim this issue and wait for the assignment before opening a PR; if two PRs show up, the assignee's stays. AI-assisted work is welcome, say so in the PR and tell us how you verified it: run the tests yourself and paste what you saw, do not describe runs you did not do. Read AGENTS.md first, it has the commands and the rules the CI enforces. This goes into 3.41.0.

Expected Behaviour

When a Redis record expires between the SET NX that fails and the GET that follows, the Redis layer behaves like the DynamoDB layer: it raises IdempotencyInconsistentStateError, which the handler's retry loop turns into a retry, and the invocation succeeds.

Current Behaviour

In CachePersistenceLayer._put_record, the GET after a failed SET NX goes through _get_record, which raises IdempotencyItemNotFoundError. That exception is not handled there, escapes _put_record and is wrapped as IdempotencyPersistenceLayerError, so the invocation fails for a race that is expected and recoverable.

Code snippet
# fake client: SET NX returns None (key existed), the following GET returns None (key expired in between)
layer = CachePersistenceLayer(client=racy_client)

@idempotent_function(data_keyword_argument="order", persistence_store=layer)
def process(order):
    return "ok"

process(order={"id": 1})  # IdempotencyPersistenceLayerError, expected: retried and "ok"

Compare with DynamoDBPersistenceLayer._put_record, where the equivalent race raises IdempotencyInconsistentStateError.

Possible Solution

In aws_lambda_powertools/utilities/idempotency/persistence/redis.py, _put_record: catch IdempotencyItemNotFoundError around the read that follows the failed SET NX and raise IdempotencyInconsistentStateError. Add a test with a fake client that returns None on that GET and assert the decorated function runs.

Item 10 of the Idempotency audit in #8603. No AWS resources needed.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

No response

Langage dominant
Python
Étoiles
3.3k
Forks
511
Merge moyen
3 j 4 h
PR mergées (30 j)
98

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de aws-powertools/powertools-lambda-python

Toutes les issues de aws-powertools/powertools-lambda-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.