Skip to content

fix(parameters): use shared cache key in get_parameters_by_name - #8614

Merged
leandrodamascena merged 3 commits into
aws-powertools:developfrom
SumiRann1:fix/parameters-shared-cache-key
Oct 29, 2026
Merged

leandrodamascena merged 3 commits into
aws-powertools:developfrom
SumiRann1:fix/parameters-shared-cache-key

Conversation

@SumiRann1

Copy link
Copy Markdown
Contributor

Issue number: closes #8593

Summary

Changes

get_parameters_by_name built its cache key by hand as (name, transform) in _get_parameters_by_name_from_cache and _transform_and_cache_get_parameters_response, while BaseProvider._build_cache_key (used by get()) 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 in ssm.py, so get() and get_parameters_by_name share cache entries. Parameters that go through the decrypt path (which calls get()) are now also found in the cache by the batch path.

I added two regression tests (get() then get_parameters_by_name, and the other way around) and updated test_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 following get_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

  • Type of change: bug fix (code change + tests added)
  • Regression tests fail before the fix and pass after it
  • Existing parameters tests pass locally (uv run pytest tests/functional/parameters)
  • ruff format and ruff check pass
  • No documentation change needed

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@SumiRann1
SumiRann1 requested a review from a team as a code owner October 18, 2026 16:40
@boring-cyborg boring-cyborg Bot added the tests label Oct 18, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 18, 2026
@leandrodamascena leandrodamascena added this to the 3.39.0 milestone Oct 19, 2026

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 29, 2026
@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@leandrodamascena
leandrodamascena merged commit 13dbc55 into aws-powertools:develop Oct 29, 2026
14 checks passed
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.99%. Comparing base (523504d) to head (0a41db8).
⚠️ Report is 1 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: get_parameters_by_name and get() use different cache keys, so they never share cache entries

2 participants