Repository navigation
fix(idempotency): read expiry from expiry_attr in CachePersistenceLayer - #8606
leandrodamascena merged 2 commits into
Conversation
_item_to_data_record read the expiry timestamp from a hardcoded "expiration" key, while records are written under self.expiry_attr. With a custom expiry_attr, records came back without expiry_timestamp: is_expired was always False, get_expiration_datetime() returned None in the response hook, and an expired record still in the cache was returned instead of running the function again.
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @Thanatos9404, two for two! I ran the suite and compared develop and your branch side by side with a custom expiry_attr: on develop an expired record that is still in Redis gets replayed forever, with your fix it re-runs like DynamoDB does, and the response hook finally sees the real expiration. Default expiration behaves exactly as before.
Approving now, this one also goes out in 3.38.0, so it will wait here a bit before I merge. No need to rebase or touch anything, I'll handle it and you'll get the credit in the release notes. Thank you!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8606 +/- ##
========================================
Coverage 96.93% 96.93%
========================================
Files 318 318
Lines 16067 16067
Branches 1430 1430
========================================
Hits 15575 15575
Misses 349 349
Partials 143 143 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|



Issue number: closes #8575
Summary
Changes
_item_to_data_recordread the expiry withitem.get("expiration"), while_put_in_progress_recordand_update_recordwrite it underself.expiry_attr. With a customexpiry_attr, every record came back withexpiry_timestamp=None. It now readsself.expiry_attr, like the other attributes.I checked the other attribute names in the same method:
in_progress_expiry_attr,status_attr,data_attrandvalidation_key_attralready use the configured names."expiration"was the only hardcoded one.Tests (added to
tests/functional/idempotency/_redis/test_redis_layer.py, each run with the defaultexpirationand a customexp):test_get_record_reads_expiry_from_expiry_attr: the snippet from the issue. ACOMPLETEDrecord stored with an expiry of1reads back withexpiry_timestamp == 1,is_expiredtrue and the matchingget_expiration_datetime().test_idempotent_function_redis_expiry_attr_round_trip: through@idempotent_functionwith aresponse_hook:None;The two
expcases fail ondevelop(expiry_timestampisNone, and the hook gets[None]); theexpirationcases pass on both. All 4 pass with this change.Checks
tests/functional/idempotencyandtests/unit/idempotency: 198 passed.ruff checkandruff format --checkon the changed files: clean.mypyonredis.py: clean.ty checkonredis.pyshows the same 8 deprecation warnings asdevelop(the deprecatedRedis*names) and nothing new.User experience
Before:
After:
1 True.What this changes for users with a custom
expiry_attr:data_record.get_expiration_datetime()in aresponse_hookreturns the expiration instead ofNone.use_local_cache=True, a record read from the cache (one written by another execution environment) is stored in the local cache with its expiry. Before, it had no expiry, so the local copy never expired and was served until it was evicted.With the default
expiry_attr, nothing changes.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.