-
Notifications
You must be signed in to change notification settings - Fork 471
Tech debt: Fix falsy response handling, inconsistencies, and duplicated code in idempotency utility #8090
Description
Why is this needed?
Found a few issues during code review of the idempotency utility:
1. Falsy responses are silently discarded (base.py:299, 273-274)
if response else None treats valid falsy return values (0, False, {}, [], "") as None. This means a function returning 0 or False won't have its response stored, and on replay it will re-execute instead of returning the cached value.
# Current
serialized_response: dict = self.output_serializer.to_dict(response) if response else None
# Should be
serialized_response: dict = self.output_serializer.to_dict(response) if response is not None else NoneSame issue on line 273-274 when reading cached responses.
2. Inconsistent status constant usage (base.py:170)
Uses string literal "INPROGRESS" instead of STATUS_CONSTANTS["INPROGRESS"].
3. str(None) produces "None" string in Redis persistence (redis.py:335-336)
response_data=str(item.get(self.data_attr)), # str(None) = "None"
payload_hash=str(item.get(self.validation_key_attr)), # str(None) = "None"When the value is missing from Redis, this creates the string "None" instead of actual None.
4. Duplicated null-check for idempotency key (persistence/base.py)
The same 4-line block is copy-pasted in save_success, save_inprogress, delete_record, and get_record:
idempotency_key = self._get_hashed_idempotency_key(data=data)
if idempotency_key is None:
# If the idempotency key is None, no data will be saved in the Persistence Layer.
# See: https://github.com/aws-powertools/powertools-lambda-python/issues/2465
return NoneCan be extracted into a single helper method to reduce duplication.
Which area does this relate to?
Idempotency
Suggestion
Fix this.
Acknowledgment
- This request meets Powertools for AWS Lambda (Python) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Java, TypeScript, and .NET
Metadata
Metadata
Assignees
Labels
Type
Projects
Status