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 None
Same 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 None
Can be extracted into a single helper method to reduce duplication.
Which area does this relate to?
Idempotency
Suggestion
Fix this.
Acknowledgment
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 Nonetreats valid falsy return values (0,False,{},[],"") asNone. This means a function returning0orFalsewon't have its response stored, and on replay it will re-execute instead of returning the cached value.Same issue on line 273-274 when reading cached responses.
2. Inconsistent status constant usage (
base.py:170)Uses string literal
"INPROGRESS"instead ofSTATUS_CONSTANTS["INPROGRESS"].3.
str(None)produces"None"string in Redis persistence (redis.py:335-336)When the value is missing from Redis, this creates the string
"None"instead of actualNone.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, andget_record:Can be extracted into a single helper method to reduce duplication.
Which area does this relate to?
Idempotency
Suggestion
Fix this.
Acknowledgment