Bug: get_parameters_by_name with raise_on_error=False still raises on transform errors in the decrypt path, and caches None
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:
_get_parameters_by_name_with_decrypt_option(:534) only catchesGetParameterError, andBaseProvider.gethard-codesraise_on_transform_error=True, so a transform failure on a decrypted parameter raisesTransformParameterErroreven in graceful mode. The same payload through the batch path returnsNone.- The batch path (
:664) caches theNonefrom a failed transform formax_ageand does not list the name in_errors, whileBaseProvider.getexplicitly avoids cachingNonefor that reason. A corrected parameter keeps returningNoneuntil 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!
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!
Hey @Suraj1347 pls go ahead.
[!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!