Commit 08c9921
fix(idempotency): resolve tech debt issues with falsy responses and Redis persistency (#8176)
* fix(idempotency): fix str(None) producing "None" string in Redis persistence
Replace str(item.get(...)) with item.get(...) to avoid storing the
string "None" when a value is missing from Redis hash map.
When data_attr or validation_key_attr is missing from Redis,
item.get() returns None. Wrapping with str() converts it to the
string "None" which is incorrect. Now correctly returns None.
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* refactor(idempotency): extract duplicated idempotency key null-check into helper method
Replace 4 identical null-check blocks across save_success, save_inprogress, delete_record, and get_record with a single helper method _get_idempotency_key_or_return_none() to reduce code duplication.
The helper encapsulates the pattern of calling _get_hashed_idempotency_key() and returning None early if the key is None, keeping each method cleaner and easier to read.
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* test(idempotency): add unit tests for tech debt fixes in issue #8090
Fix 1 - str(None) in Redis _item_to_data_record:
- Missing data_attr returns None not string "None"
- Existing data_attr returns value correctly
- Demonstrates old bug vs new correct behavior
Fix 2 - _get_idempotency_key_or_return_none helper:
- Returns None when key is None
- Returns key string when key exists
- Correctly used in save_success, save_inprogress,
delete_record, and get_record (all return None early)
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* fix(idempotency): fix falsy response handling and inconsistent status constant
Fix 1 - Falsy response handling in _get_function_response(): Replace `if response else None` with `if response is not None else None`. So valid falsy return values (0, False, {}, [], "") are correctly serialized and stored instead of being silently discarded.
Fix 2 - Inconsistent status constant in _process_idempotency():
Replace string literal "INPROGRESS" with STATUS_CONSTANTS["INPROGRESS"] for consistency with the rest of the codebase.
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* refactor(idempotency): revert helper method - restore original inline null-check pattern
Per Leandro Damascena's feedback: _get_idempotency_key_or_return_none() helper added
indirection without reducing duplication since the if None: return None check remained in all 4 callers anyway.
Restored original inline 3-line pattern in save_success, save_inprogress, delete_record, and get_record which is clearer and instantly readable.
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* test(idempotency): remove standalone test file per maintainer feedback
Tests should be added to existing test files following established patterns, not in new standalone files. The Redis fix will be tested in
_redis/test_redis_layer.py next to the existing test_item_to_datarecord_conversion.
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* test(idempotency): add regression test for str(None) fix in _item_to_data_record
Added single test next to existing test_item_to_datarecord_conversion to verify missing Redis attributes return None instead of string "None".
Follows existing test patterns using fixtures instead of MagicMock.
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* fix(idempotency): fix ruff formatting - remove trailing whitespace in base.py
Remove trailing whitespace on blank line between is_missing_idempotency_key
and _get_hashed_payload methods to pass ruff format check.
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* fix(idempotency): fix test fixture name and trailing whitespace in test_redis_layer.py
- Fix fixture name from persistence_store_redis to persistence_store_standalone_redis
to match existing fixture defined in the test file
- Remove trailing whitespace on blank line after test function to pass ruff format check
Part of #8090
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
* fix: small changes
---------
Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
Co-authored-by: Leandro Damascena <lcdama@amazon.pt>1 parent 0834363 commit 08c9921
3 files changed
Lines changed: 23 additions & 4 deletions
File tree
- aws_lambda_powertools/utilities/idempotency
- persistence
- tests/functional/idempotency/_redis
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
336 | | - | |
| 335 | + | |
| 336 | + | |
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
333 | 352 | | |
334 | 353 | | |
335 | 354 | | |
| |||
0 commit comments