Repository navigation
fix(parameters): use shared cache key in get_parameters_by_name - #8614
leandrodamascena merged 3 commits into
Conversation
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @SumiRann1, the two places you changed are the right ones. Problem is #8619 landed while this was open and changed the key shape again, so this needs an update.
SSMProvider.get() always passes decrypt in sdk_options, so its key on develop today is (name, transform, False, '{"decrypt": false}'). Your batch key is (name, transform, False). Still different, and your two new tests fail after a rebase. Pass sdk_options={"decrypt": options["decrypt"]} to _build_cache_key in both spots and fix the expected key in test_get_parameters_by_name_cache. I tried it locally against real Parameter Store and both directions share the cache after that.
This also fixes something worse I noticed while testing: the batch path caches a SecureString under the same key with or without decrypt, so a second batch call without decrypt gets the decrypted value from cache. Please add a test for that: two batch calls, one with decrypt=True, one without, both must hit the API.
Rebase on develop too, the conflict is only in the test file, keep both blocks. Ping me when it's ready. This is in 3.39.0.
get() stores entries under (name, transform, is_nested, sdk_options) since aws-powertools#8619, so the batch path needs the same shape to share cache. Including decrypt also stops a SecureString fetched with decrypt=True from being served from cache to a later call without it.
|
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @SumiRann1, I went ahead and finished this one since 3.39.0 is closing. I merged develop into your branch and pushed one commit on top: both batch sites now pass sdk_options={"decrypt": options["decrypt"]} to _build_cache_key, so the key matches what get() writes. I also fixed the expected keys in the three tests that still had the old tuple and added two tests for the decrypt case.
Tested against real Parameter Store in both directions, and the decrypt isolation too: on develop a batch call without decrypt was getting the decrypted SecureString from cache after a batch call with decrypt=True, with this change it calls the API again and gets the ciphertext. Your commit stays as the first one in the PR so the credit is yours. Approving, this goes out in 3.39.0.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8614 +/- ##
========================================
Coverage 96.99% 96.99%
========================================
Files 321 321
Lines 16332 16332
Branches 1473 1473
========================================
Hits 15841 15841
Misses 350 350
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



Issue number: closes #8593
Summary
Changes
get_parameters_by_namebuilt its cache key by hand as(name, transform)in_get_parameters_by_name_from_cacheand_transform_and_cache_get_parameters_response, whileBaseProvider._build_cache_key(used byget()) builds(name, transform, is_nested). The two never matched, so the same parameter was fetched twice and stored twice.This PR uses
self._build_cache_key(...)in both places inssm.py, soget()andget_parameters_by_nameshare cache entries. Parameters that go through the decrypt path (which callsget()) are now also found in the cache by the batch path.I added two regression tests (
get()thenget_parameters_by_name, and the other way around) and updatedtest_get_parameters_by_name_cache, which hardcoded the old key shape(name, None).User experience
Before: a parameter fetched with
get("/a")was fetched again by a followingget_parameters_by_name({"/a": {}})even though it was still fresh in cache (extra API call, duplicate cache entry), and vice versa.After: the fresh cached value is reused in both directions.
Checklist
uv run pytest tests/functional/parameters)ruff formatandruff checkpassBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.