Skip to content

Commit 8e0217c

Browse files
committed
refactor: validate before saving to cache
1 parent e760bf2 commit 8e0217c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

aws_lambda_powertools/utilities/idempotency/persistence/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Persistence layers supporting idempotency
33
"""
4+
45
import datetime
56
import hashlib
67
import json
@@ -383,9 +384,9 @@ def get_record(self, data: Dict[str, Any]) -> Optional[DataRecord]:
383384

384385
record = self._get_record(idempotency_key=idempotency_key)
385386

387+
self._validate_payload(data_payload=data, stored_data_record=record)
386388
self._save_to_cache(data_record=record)
387389

388-
self._validate_payload(data_payload=data, stored_data_record=record)
389390
return record
390391

391392
@abstractmethod

aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ def _put_record(self, data_record: DataRecord) -> None:
259259
f"expiry_timestamp: {old_data_record.expiry_timestamp}, "
260260
f"and in_progress_expiry_timestamp: {old_data_record.in_progress_expiry_timestamp}",
261261
)
262-
self._save_to_cache(data_record=old_data_record)
263262

264263
try:
265264
self._validate_payload(data_payload=data_record, stored_data_record=old_data_record)
265+
self._save_to_cache(data_record=old_data_record)
266266
except IdempotencyValidationError as idempotency_validation_error:
267267
raise idempotency_validation_error from exc
268268

0 commit comments

Comments
 (0)