Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key value

Đang mở Phù hợp với người mới
#8,724 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@sumedh-aerram đang làm issue này rồi.

Từ ngày 31/10/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
90/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
aws, python
Lĩnh vực
databases

Hướng nghiên cứu

Đọc aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py, tập trung vào _item_to_data_record. Thay đổi idempotency_key để sử dụng sort_key_attr khi được thiết lập. Thêm các test sử dụng botocore.stub.Stubber trên client của lớp với sort_key_attr và một response_hook để xác nhận khóa, cộng với một test trúng cache cục bộ. Hoàn thành khi các test mới qua và khóa phản ánh giá trị sắp xếp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

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

Ngôn ngữ chính
Python
Star
3.3k
Fork
511
Merge trung bình
3 ngày 12 giờ
Pull request đã merge (30 ngày)
93

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aws-powertools/powertools-lambda-python

Tất cả issue của aws-powertools/powertools-lambda-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.