Bug: CachePersistenceLayer raises IdempotencyValidationError on retries with the same payload when payload_validation_jmespath is set
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 83/100
Rechercherichtung
Beginne in der Redis-Persistenzschicht bei CachePersistenceLayer._update_record und vergleiche dann dessen Mapping mit _put_in_progress_record und dem _update_record der DynamoDB-Schicht. Füge neben test_idempotent_function_and_lambda_handler_redis_validation einen Regressionstest hinzu, der mit derselben Payload einen erneuten Versuch durchführt und überprüft, dass die gespeicherte Antwort zurückgegeben wird. Fertig ist die Arbeit, wenn der Payload-Validierungshash den Abschluss übersteht und der erneute Versuch erfolgreich ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 3.3k
- Forks
- 511
- Ø Merge
- 3 T. 4 Std.
- Gemergte PRs (30 T.)
- 98
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus aws-powertools/powertools-lambda-python
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationEvtl. vergeben @lechakrawarthy hat das vor 3 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8728 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GETEvtl. vergeben @coughlmao hat das vor 3 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8727 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 secondsEvtl. vergeben @CJstate hat das vor 3 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
aws-powertools/powertools-lambda-python#8726 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashedEvtl. vergeben @Neeraj111010 hat das vor 3 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
aws-powertools/powertools-lambda-python#8725 · 6 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key valueEvtl. vergeben @sumedh-aerram hat das vor 3 Tagen übernommen. Offenbug good first issue help wanted idempotency
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
aws-powertools/powertools-lambda-python#8724 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in aws-powertools/powertools-lambda-python
Ähnliche Issues
-
bug ready-for-dev
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 92/100
OpenHands/extensions#897 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
tensorflow/datasets#11253 ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix(core): a config section with all keys commented out crashes startupEvtl. vergeben @Aryanbhargava18 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
kubeflow/mcp-server#512 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Stop trusting the compromised eMudhra CA certificatesEvtl. vergeben @anth-volk hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
PolicyEngine/uk-triple-lock#54 ·
Maintainer antworten meist innerhalb von 1 Tag
-
DBFS append mode silently overwrites existing filesEvtl. vergeben @IlyaKhalafi hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
fsspec/filesystem_spec#2429 ·
Maintainer antworten meist innerhalb von 1 Tag