Repository navigation
fix(parameters): ignore malformed POWERTOOLS_PARAMETERS_MAX_AGE instead of crashing - #8757
Open
AP24110011695 wants to merge 1 commit into
Open
AP24110011695 wants to merge 1 commit into
AP24110011695 wants to merge 1 commit into
Conversation
…ad of crashing An empty or non-integer POWERTOOLS_PARAMETERS_MAX_AGE crashed every parameters, secrets and AppConfig lookup with a raw ValueError from int() before any AWS call was made (13 call sites share one resolver). Resolve the variable through a helper that falls back to the documented default with a PowertoolsUserWarning naming the ignored value (ADR 0006: warn now, harden in a future major), mirroring the aws-powertools#8734 approach for POWERTOOLS_IDEMPOTENCY_DISABLED. Recognized integer values, including 0 (no caching), behave exactly as before. Regression test fails on develop with the ValueError and passes with the fix for both malformed values.
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Issue number: closes #8747
Summary
Changes
resolve_max_age()is a rawint(env), so an empty or non-integerPOWERTOOLS_PARAMETERS_MAX_AGEraisedValueErrorfrom every Parameters/Secrets/AppConfig entry point (12 call sites) before any AWS call was made.resolve_parameters_max_age()inutilities/parameters/base.py: an explicitchoicealways wins; otherwise the environment variable is parsed, and aValueErroremits aPowertoolsUserWarningnaming the ignored value and falls back to the documented default (DEFAULT_MAX_AGE_SECS= 300s), per ADR 0006 (warn now, harden in a future major).resolve_max_age, andos/constants/DEFAULT_MAX_AGE_SECSwhere no longer used) removed.PowertoolsUserWarningper ADR 0006 rather than a debug log — happy to align with fix(idempotency): treat empty or unparsable POWERTOOLS_IDEMPOTENCY_DISABLED as not disabled #8734's debug-log style if you prefer the two byte-identical.0(no caching) — behave exactly as before.User experience
Before:
POWERTOOLS_PARAMETERS_MAX_AGE=""(a common config-drift case) madeget_parameter(),get_secret(),SSMProvider().get()and every other lookup raiseValueError: invalid literal for int() with base 10: ''until the environment was fixed.After: the same calls succeed with the documented default caching age, and one warning names the ignored value so the typo is visible.
Verification
test_ssm_provider_get_with_invalid_max_age_env_var(tests/functional/parameters/_boto3/test_utilities_parameters.py): ondevelop(bc3136c) it fails with the reportedValueError; with this change it passes for both""and"abc", asserting the warning, the returned value, and that the SDK call still happens.uv run pytest tests/functional/parameters tests/unit/test_shared_functions.py: 263 passed.uv run pytest tests/functional/feature_flags: 191 passed.uv run pytest tests/unit: 626 passed; the 8 failures are pre-existing on cleandevelopon this machine (missing optional extras aws_xray_sdk etc.) and unrelated to this change.uv run mypy aws_lambda_powertools/utilities/parameters/: clean;ruff format+ruff checkclean on all touched files.developbefore filing Bug: POWERTOOLS_PARAMETERS_MAX_AGE set to an empty or non-integer value crashes every parameters call #8747 (empty and non-integer crash; unset baseline reaches the SDK).This PR was prepared with AI assistance; the repro, tests and every run above were executed and verified by me against
develop(bc3136c) as described.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.