Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocation

未關閉 適合新手
#8,728 4 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 1 天內回覆

@lechakrawarthy 已經在處理了。

開始於 2026年11月1日。

  • #8734 來自 @lechakrawarthy —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
85/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
aws, python
領域
backend

研究方向

從 aws_lambda_powertools/utilities/idempotency/idempotency.py 開始,其中兩個裝飾器都呼叫了 strtobool。檢查 aws_lambda_powertools/shared/functions.py 中的 resolve_truthy_env_var_choice 是否合適,否則新增一個對空或無法解析的值回傳 False 的 helper。新增測試,使得空、"maybe" 和未設定執行該函式,而 "true" 跳過 idempotency;完成意味著沒有 ValueError 且 CI 通過。

由索引模型根據 Issue 內容生成。

描述

bug good first issue help wanted idempotency

[!WARNING]
For contributors, human or agent. Comment here to claim this issue and wait for the assignment before opening a PR; if two PRs show up, the assignee's stays. AI-assisted work is welcome, say so in the PR and tell us how you verified it: run the tests yourself and paste what you saw, do not describe runs you did not do. Read AGENTS.md first, it has the commands and the rules the CI enforces. This goes into 3.41.0.

Expected Behaviour

POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty string or to a value that is not a recognised boolean is treated as "not disabled", possibly with a warning. Only truthy values disable idempotency.

Current Behaviour

Both idempotent and idempotent_function call strtobool(os.getenv("POWERTOOLS_IDEMPOTENCY_DISABLED", "false")), and strtobool("") raises ValueError: invalid truth value '', so every invocation crashes before the handler runs. "0", "no" and "False" work. An empty value is easy to end up with in IaC templates and CI variables.

Code snippet
import os
os.environ["POWERTOOLS_IDEMPOTENCY_DISABLED"] = ""

@idempotent_function(data_keyword_argument="order", persistence_store=layer)
def process(order):
    return "ok"

process(order={"id": 1})  # ValueError: invalid truth value ''
Possible Solution

In aws_lambda_powertools/utilities/idempotency/idempotency.py, resolve the variable once with a helper that returns False for empty or unparsable values (and logs a debug message), and use it in both decorators. Check whether resolve_truthy_env_var_choice in aws_lambda_powertools/shared/functions.py already fits. Tests: "", "maybe" and unset all run the function; "true" skips idempotency.

Item 11 of the Idempotency audit in #8603. No AWS resources needed.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

No response

主要語言
Python
星號
3.3k
分支
511
平均合併
3 天 8 小時
30 天內合併 PR
92

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws-powertools/powertools-lambda-python 的其他 Issue

查看 aws-powertools/powertools-lambda-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。