Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key value
維護者通常 1 天內回覆
評估
研究方向
閱讀 aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py,重點查看 _item_to_data_record。將 idempotency_key 改為在設定時使用 sort_key_attr。在 layer 的 client 上使用 botocore.stub.Stubber 新增測試,配合 sort_key_attr 與一個 response_hook 來斷言該鍵,另外加一個本地快取命中測試。當新測試通過且鍵反映出排序值時完成。
由索引模型根據 Issue 內容生成。
描述
[!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
With a composite key (sort_key_attr set), DataRecord.idempotency_key is the record's own key, the value stored in the sort key, so the local cache, the response_hook and the IdempotencyAlreadyInProgressError message refer to the actual record.
Current Behaviour
DynamoDBPersistenceLayer._item_to_data_record sets idempotency_key=data[self.key_attr], which with a composite key is the static partition key value (static_pk_value, idempotency#<function> by default) for every record. So use_local_cache stores every record under one key and never hits for records written elsewhere, the response_hook receives idempotency_key='idempotency#myfn' (the docs example reads that field), and the in-progress error message shows the static value.
Code snippet
from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer
layer = DynamoDBPersistenceLayer(table_name="t", sort_key_attr="sk", static_pk_value="idempotency#fn")
record = layer._item_to_data_record(
{"id": {"S": "idempotency#fn"}, "sk": {"S": "fn#abc"}, "status": {"S": "COMPLETED"}, "expiration": {"N": "9999999999"}, "data": {"S": "{}"}},
)
record.idempotency_key # 'idempotency#fn', expected 'fn#abc'
For the public-API test, use botocore.stub.Stubber on the layer's client like the existing composite-key tests do, and assert on what the response_hook receives.
Possible Solution
In aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py, _item_to_data_record: idempotency_key=data[self.sort_key_attr] if self.sort_key_attr else data[self.key_attr]. Add a test with sort_key_attr and a response_hook asserting the key, and one for the local cache hit.
Item 7 of the Idempotency audit in #8603. No AWS resources needed, the existing tests stub DynamoDB.
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
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
aws-powertools/powertools-lambda-python 的其他 Issue
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocation可能已有人在做 @lechakrawarthy 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 85/100
aws-powertools/powertools-lambda-python#8728 · 4 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GET可能已有人在做 @coughlmao 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 85/100
aws-powertools/powertools-lambda-python#8727 · 4 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 seconds可能已有人在做 @CJstate 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 75/100
aws-powertools/powertools-lambda-python#8726 · 3 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashed可能已有人在做 @Neeraj111010 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 80/100
aws-powertools/powertools-lambda-python#8725 · 4 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Bug: output_serializer=PydanticSerializer crashes at import under from __future__ import annotations可能已有人在做 @sumedh-aerram 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 80/100
aws-powertools/powertools-lambda-python#8722 · 6 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 aws-powertools/powertools-lambda-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 82/100
Nixtla/mlforecast#823 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
microsoft/ML-For-Beginners#1061 ·
-
bot-found documentation priority: P3
難度 2/5 1 小時以內 新手友好度 82/100
madenvel/KalinkaPlayer#503 ·
-
難度 2/5 1-3 小時 新手友好度 63/100
EleutherAI/lm-evaluation-harness#4508 ·
維護者通常 1 天內回覆