Repository navigation
fix(idempotency): treat empty or unparsable POWERTOOLS_IDEMPOTENCY_DISABLED as not disabled - #8734
lechakrawarthy wants to merge 4 commits into
Conversation
…SABLED as not disabled
strtobool("") raised ValueError, so an empty or non-boolean value crashed
every invocation before the handler ran. Resolve the variable once in a
helper that returns False (with a debug log) for values strtobool rejects,
and use it in both idempotent and idempotent_function.
308f637 to
364b675
Compare
|
Thanks for the PR and for filling in the verification section, that helps. Heads up that the review may take a few days: this goes into 3.41.0 and I review every PR against a real service before approving, one at a time. No need to rebase or ping in the meantime, I'll come back here. |
|
Thanks @lechakrawarthy, and sorry for the detour. Your fix was right; what changed in the meantime is that #8783 landed a shared |
|
…ad of crashing (#8757) 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 #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. Co-authored-by: Ayush Kumar Saha <[email protected]> Co-authored-by: Leandro Damascena <[email protected]>



Issue number:
closes #8728
Summary
Changes
idempotentandidempotent_functionboth calledstrtobool(os.getenv("POWERTOOLS_IDEMPOTENCY_DISABLED", "false")), andstrtoboolraisesValueErrorfor an empty string or any non-boolean value, so every invocation crashed before the handler ran._is_idempotency_disabled()inidempotency.py. It resolves the variable once and returnsFalsefor valuesstrtoboolrejects, with a debug log saying the value was ignored. Recognised values behave exactly as before.resolve_truthy_env_var_choicefromshared/functions.py: it calls the samestrtobooland raises the same way, and changing it would change behaviour for every utility that uses it.Tests
Added
test_idempotency_disabled_envvar_empty_or_unparsableintests/functional/idempotency/_boto3/test_idempotency.py, next to the existing env var tests. It runs both decorators with""," ","maybe"and the variable unset, and checks the functions return their result and the persistence layer is still called (idempotency stays on). The existing truthy and falsy cases are unchanged and still pass.Verification
Ran locally on Windows (
uv sync --locked --extra all --extra redis --extra datamasking; thevalkeyextra does not build on Windows).New test on
develop, before the fix:With the fix:
After that run I split the debug log string over two lines (ruff E501) and re-ran the env var tests, ruff and mypy:
AI disclosure
This change was made with the help of an AI coding assistant. I ran the commands above and the output is pasted as seen.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.