Bug: CachePersistenceLayer raises IdempotencyValidationError on retries with the same payload when payload_validation_jmespath is set
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 83/100
Piste de recherche
Commencez dans la couche de persistance Redis, au niveau de CachePersistenceLayer._update_record, puis comparez son mapping avec _put_in_progress_record et celui de _update_record dans la couche DynamoDB. Ajoutez un cas de régression à côté de test_idempotent_function_and_lambda_handler_redis_validation qui réessaie avec la même charge utile et vérifie que la réponse stockée est renvoyée. Le travail est terminé lorsque le hash de validation de la charge utile est conservé après la finalisation et que la nouvelle tentative réussit.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Expected Behaviour
With CachePersistenceLayer (Redis/Valkey) and payload_validation_jmespath set, a retry with the same payload should return the stored response, the same way it does with DynamoDBPersistenceLayer.
Current Behaviour
The second call with the exact same payload raises IdempotencyValidationError: Payload does not match stored record for this event key.
_put_in_progress_record stores the payload hash under validation_key_attr, but _update_record overwrites the whole key with a new SET that only contains data, status and expiration. The hash is lost when the record moves to COMPLETED, so on the next call payload_hash is read back as "" and never matches.
DynamoDBPersistenceLayer._update_record writes the validation key when payload_validation_enabled is true, so only the Redis layer is affected.
Code snippet
from aws_lambda_powertools.utilities.idempotency import IdempotencyConfig, idempotent_function
from aws_lambda_powertools.utilities.idempotency.persistence.redis import CachePersistenceLayer
class InMemoryClient:
"""Minimal client with the get/set/delete calls the layer uses."""
def __init__(self):
self.store = {}
def get(self, name):
return self.store.get(name)
def set(self, name, value, ex=0, nx=False):
if nx and name in self.store:
return None
self.store[name] = value
return True
def delete(self, name):
self.store.pop(name, None)
client = InMemoryClient()
persistence_layer = CachePersistenceLayer(client=client)
config = IdempotencyConfig(event_key_jmespath="order_id", payload_validation_jmespath="amount")
@idempotent_function(data_keyword_argument="order", persistence_store=persistence_layer, config=config)
def process_order(order):
return {"order_id": order["order_id"]}
order = {"order_id": "o-1", "amount": 10}
print(process_order(order=order)) # {'order_id': 'o-1'}
print(list(client.store.values())[0]) # no "validation" field in the stored record
print(process_order(order=order)) # IdempotencyValidationError
Possible Solution
Add the validation key to the mapping in CachePersistenceLayer._update_record, like _put_in_progress_record already does:
if self.payload_validation_enabled:
item["mapping"][self.validation_key_attr] = data_record.payload_hash
The existing test test_idempotent_function_and_lambda_handler_redis_validation only covers a different payload, so a test for a same-payload retry would catch this. I'm happy to send a PR.
Steps to Reproduce
Run the snippet above. No Redis server is needed, the in-memory client follows the same get/set/delete calls. The same happens with a real Redis or Valkey client.
Powertools for AWS Lambda (Python) version
latest (also on develop)
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
aws_lambda_powertools.utilities.idempotency.exceptions.IdempotencyValidationError: Payload does not match stored record for this event key
- 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 layer fails the invocation instead of retrying when a record expires between SET NX and GETPeut-être pris @coughlmao 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#8727 · 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
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