powertools-lambda-python icon indicating copy to clipboard operation
powertools-lambda-python copied to clipboard

Bug: get_parameters_by_name with raise_on_error=False still raises on transform errors in the decrypt path, and caches None

Open leandrodamascena opened this issue 1 month ago • 4 comments

Expected Behaviour

With raise_on_error=False, a parameter whose transform fails is reported in _errors and does not stop the call, no matter whether it was fetched with GetParameter (decrypt) or GetParameters (batch). Failed transforms are not cached.

Current Behaviour

Two related problems in ssm.py:

  1. _get_parameters_by_name_with_decrypt_option (:534) only catches GetParameterError, and BaseProvider.get hard-codes raise_on_transform_error=True, so a transform failure on a decrypted parameter raises TransformParameterError even in graceful mode. The same payload through the batch path returns None.
  2. The batch path (:664) caches the None from a failed transform for max_age and does not list the name in _errors, while BaseProvider.get explicitly avoids caching None for that reason. A corrected parameter keeps returning None until the cache expires.

Code snippet

from botocore.config import Config
from botocore.stub import Stubber
from aws_lambda_powertools.utilities.parameters import SSMProvider

provider = SSMProvider(boto_config=Config(region_name="us-east-1"))
stub = Stubber(provider.client)
stub.add_response("get_parameter", {"Parameter": {"Name": "/a", "Value": "not json", "Type": "String", "Version": 1}}, {"Name": "/a", "WithDecryption": True})
stub.add_response("get_parameters", {"Parameters": [{"Name": "/b", "Value": "not json", "Type": "String", "Version": 1}]}, {"Names": ["/b"]})
stub.activate()

provider.get_parameters_by_name({"/a": {"decrypt": True}, "/b": {}}, transform="json", raise_on_error=False)
# TransformParameterError      expected: {'_errors': ['/a', '/b'], ...}

provider.get_parameters_by_name({"/b": {}}, transform="json", raise_on_error=False)
# {'_errors': [], '/b': None}  and provider.store now caches None for /b

Possible Solution

Catch TransformParameterError in the decrypt path and add the name to errors; in the batch path, skip add_to_cache when the transformed value is None and add the name to _errors.

Steps to Reproduce

Run the snippet above (it uses botocore.stub.Stubber, no AWS access needed).

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs


[!WARNING] This issue is ready to be picked up, by humans or by agents. If you want it, comment here first so we can assign it to you, and please take only one or two issues at a time so others can join in too. The reproduction above runs locally without AWS access. Thanks!

leandrodamascena avatar Oct 18 '26 11:10 leandrodamascena

Hi! I'd like to work on this issue as my first open-source contribution.

I plan to investigate the decrypt-path transformation error handling and the caching of failed transformations, then propose a focused fix with regression tests for both cases.

Could you please confirm that this scope is appropriate and assign the issue to me before I start? Thank you!

Suraj1347 avatar Oct 18 '26 15:10 Suraj1347

Hey @Suraj1347 pls go ahead.

leandrodamascena avatar Oct 18 '26 16:10 leandrodamascena

[!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.

This is now released under 3.39.0 version!

github-actions[bot] avatar Nov 03 '26 13:11 github-actions[bot]