Skip to content

Bug: AppConfigProvider retrieves wrong value #2362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scottgerring opened this issue Jun 2, 2023 · 4 comments · Fixed by #2378
Closed

Bug: AppConfigProvider retrieves wrong value #2362

scottgerring opened this issue Jun 2, 2023 · 4 comments · Fixed by #2378
Assignees
Labels
bug Something isn't working parameters Parameters utility

Comments

@scottgerring
Copy link

scottgerring commented Jun 2, 2023

Expected Behaviour

When I call parameters.get_parameter using the AppConfigProvider more than once with different parameter names, I expect to get the corresponding values for each configuration profiles in AppConfig.

The code in the _get method on AppConfigProvider stores the configuration session from the first time it is called and re-uses it. The problem is that the configuration session is associated with a single configuration profile, and you can see that the name parameter is ignored once a session is started. Here you can see the retrieval and storage of the token irrespective of the name of the field:

https://github.com/awslabs/aws-lambda-powertools-python/blob/5aece716496e1ce4220b2f2dcb399eceaefc976b/aws_lambda_powertools/utilities/parameters/appconfig.py#L100-L116

I've also noticed that DEFAULT_PROVIDERS holds a copy of an AppConfigProvider established using the application and environment from the first call, and re-uses it:

https://github.com/awslabs/aws-lambda-powertools-python/blob/5aece716496e1ce4220b2f2dcb399eceaefc976b/aws_lambda_powertools/utilities/parameters/appconfig.py#L198-L202

I think this means that we'll also not be able to provide a different application or environment for subsequent calls - in this case, I imagine it could be by design (a running application has a single identity and a single environment?)

Current Behavior

The first call works as expected, the second call returns the value from the configuration profile associated with the first call.

Code snippet

These will both end up with the value of param1:

        param_1 = parameters.get_app_config(name="param1", environment="dev", application="example")
        param_2 = parameters.get_app_config(name="param2", environment="dev", application="example")

Possible Solution

Powertools for typescript stores the session tokens keyed on the parameter / configuration profile name:

https://github.com/awslabs/aws-lambda-powertools-typescript/blob/0021536e35ba7046226155055f9ab6b5f988f71f/packages/parameters/src/appconfig/AppConfigProvider.ts#L264-L270

Steps to Reproduce

Fetch two different parameters within the same lambda execution

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.7

Packaging format used

PyPi

Debugging logs

No response

@scottgerring scottgerring added bug Something isn't working triage Pending triage from maintainers labels Jun 2, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 2, 2023

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@leandrodamascena leandrodamascena self-assigned this Jun 2, 2023
@leandrodamascena leandrodamascena added parameters Parameters utility and removed triage Pending triage from maintainers labels Jun 2, 2023
@leandrodamascena
Copy link
Contributor

Thanks for opening this issue @scottgerring! I'll review the code again to see how best we can fix this.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2023

⚠️COMMENT VISIBILITY 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 tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jun 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2023

This is now released under 2.16.2 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parameters Parameters utility
Projects
None yet
2 participants