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

Aberta Para iniciantes
#8,724 3 comentários 0 reações 1 responsável Ver no GitHub

Mantenedores costumam responder em até 1 dia

@sumedh-aerram já está trabalhando nisso.

Desde 1/11/2026.

  • #8739 de @sumedh-aerram — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
90/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
aws, python
Domínio
databases

Direção de pesquisa

Leia aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py, focando em _item_to_data_record. Mude idempotency_key para usar sort_key_attr quando definido. Adicione testes usando botocore.stub.Stubber no cliente da camada com sort_key_attr e um response_hook para verificar a chave, além de um teste de acerto de cache local. Pronto quando os novos testes passarem e a chave refletir o valor de ordenação.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
Python
Estrelas
3.3k
Forks
511
Merge médio
3d 8h
PRs com merge (30d)
92

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de aws-powertools/powertools-lambda-python

Todas as issues de aws-powertools/powertools-lambda-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.