You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: LRUDict.get raises for missing keys with truthy defaults #8682
LRUDict.get("missing", "fallback") returns "fallback", matching dict.get and OrderedDict.get. Reading an existing entry should make it recently used even when its value is falsey.
Current Behaviour
A missing key with a truthy default raises KeyError because get calls move_to_end on the missing key. An existing entry containing False, 0, or None is returned without updating its recency, so it can be evicted immediately after being read.
Code snippet
fromaws_lambda_powertools.shared.cache_dictimportLRUDictcache=LRUDict(max_items=2)
cache.get("missing", "fallback") # Raises KeyError: 'missing'cache["false_value"] =Falsecache["other"] =1cache.get("false_value")
cache["new"] =2assert"false_value"incache# Fails: the recently read key was evicted
Steps to Reproduce
Run the snippet against the current develop branch (5785377) on Python 3.12. The first expression raises KeyError; if skipped, the final assertion fails.
Possible Solution
Check whether the key exists before moving it to the end. Preserve the normal get return behavior for a missing key and its optional default.
Environment
Powertools for AWS Lambda (Python): source checkout at 5785377 (develop)
Python: 3.12
Packaging: source checkout; no Lambda runtime or AWS service is needed
LRUDict is an internal shared cache, so the current impact depends on how callers use get. This report concerns its mapping and recency behavior.
Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link
Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out our GitHub Discussions: Join the conversation
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
Activity
boring-cyborg commentedon Oct 26, 2026
Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link
powertools-for-aws-oss-automation commentedon Oct 26, 2026
Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out our GitHub Discussions: Join the conversation
powertools-for-aws-oss-automation commentedon Oct 29, 2026
Warning
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
github-actions commentedon Nov 3, 2026
This is now released under 3.39.0 version!