Skip to content

fix(parameters): avoid mutating caller's dict in get_parameters_by_name - #8607

Merged
leandrodamascena merged 3 commits into
aws-powertools:developfrom
SumiRann1:fix/get-parameters-by-name
Oct 22, 2026
Merged

leandrodamascena merged 3 commits into
aws-powertools:developfrom
SumiRann1:fix/get-parameters-by-name

Conversation

@SumiRann1

Copy link
Copy Markdown
Contributor

Issue number: closes #8590

Summary

Changes

SSMProvider._split_batch_and_decrypt_parameters (used by get_parameters_by_name) did _overrides = options or {}, which made _overrides the same object as the caller's per-parameter dict. The following writes of transform, decrypt and max_age therefore modified the user's input. On later calls, those stale values took precedence over the new global decrypt/transform.

This PR copies the dict instead (_overrides = {**(options or {})}), so the caller's input is never modified. I also added a regression test.

User experience

Before: reusing the same parameters dict (e.g. a module-level PARAMS = {...}, as in the docs) across invocations mutated it on the first call. A later call such as get_parameters_by_name(PARAMS, decrypt=True) silently fetched parameters without decryption, because the stale decrypt=False from the first call won.

After: the input dict is left untouched, and global decrypt/transform passed on each call are honored.


Checklist

  • Type of change: bug fix (code change + test added)
  • Regression test added: test_ssm_provider_get_parameters_by_name_does_not_mutate_input_and_honors_new_globals
  • Test fails before the fix and passes after it
  • Existing parameters tests pass locally (uv run pytest tests/functional/parameters)
  • ruff format and ruff check pass
  • No documentation change needed (behaviour now matches what the docs already describe)

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 12:17
@SumiRann1
SumiRann1 requested a review from hjgraca October 18, 2026 12:17
@boring-cyborg

boring-cyborg Bot commented Oct 18, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@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, nice first one! I ran the suite and checked a few extra cases with the stubber: the caller's dict stays untouched, a later decrypt=True or transform="json" is honored, and per-parameter overrides still win over the globals like before. I pushed a tiny commit fixing a typo that slipped into a comment (qparameters), nothing else.

Approving now. This goes out in 3.38.0, so it will sit here a bit before I merge. No need to rebase or touch anything, I'll take care of it and you'll get the credit in the release notes. Thank you!

@SumiRann1 SumiRann1 left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it! Thanks for pointing out

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.93%. Comparing base (2af58c0) to head (71e8bbf).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8607   +/-   ##
========================================
  Coverage    96.93%   96.93%           
========================================
  Files          318      318           
  Lines        16067    16067           
  Branches      1433     1433           
========================================
  Hits         15575    15575           
  Misses         349      349           
  Partials       143      143           

☔ 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.

@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena
leandrodamascena merged commit f94134e into aws-powertools:develop Oct 22, 2026
12 checks passed
@boring-cyborg

boring-cyborg Bot commented Oct 22, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@powertools-for-aws-oss-automation

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

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

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: get_parameters_by_name mutates the caller's parameters dict, so later global decrypt/transform are ignored

2 participants