Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GET
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 85/100
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
[!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
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de aws-powertools/powertools-lambda-python
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationPeut-être pris @lechakrawarthy l’a pris il y a 3 jours. Ouvertebug good first issue help wanted idempotency
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
aws-powertools/powertools-lambda-python#8728 · 4 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 secondsPeut-être pris @CJstate l’a pris il y a 3 jours. Ouvertebug good first issue help wanted idempotency
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
aws-powertools/powertools-lambda-python#8726 · 3 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashedPeut-être pris @Neeraj111010 l’a pris il y a 3 jours. Ouvertebug good first issue help wanted idempotency
Difficulté 2/5 1-3 heures Accessibilité débutants 80/100
aws-powertools/powertools-lambda-python#8725 · 6 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key valuePeut-être pris @sumedh-aerram l’a pris il y a 3 jours. Ouvertebug good first issue help wanted idempotency
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
aws-powertools/powertools-lambda-python#8724 · 3 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Bug: output_serializer=PydanticSerializer crashes at import under from __future__ import annotationsPeut-être pris @sumedh-aerram l’a pris il y a 3 jours. Ouvertebug good first issue help wanted idempotency
Difficulté 2/5 1-3 heures Accessibilité débutants 80/100
aws-powertools/powertools-lambda-python#8722 · 6 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de aws-powertools/powertools-lambda-python
Issues similaires
-
DBFS append mode silently overwrites existing filesPeut-être pris @IlyaKhalafi l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
fsspec/filesystem_spec#2429 ·
Les mainteneurs répondent en général sous 1 jour
-
[Bug]: Retrieval rerank fallback statistics stay zero after provider failurePeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
volcengine/OpenViking#7014 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
fedora-copr/copr#4600 ·
Les mainteneurs répondent en général sous 2 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
ansys/pydpf-core#3620 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour