Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key value
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 90/100
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
[!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
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de aws-powertools/powertools-lambda-python
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationTalvez já em andamento @lechakrawarthy assumiu hoje. Abertabug good first issue help wanted idempotency
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
aws-powertools/powertools-lambda-python#8728 · 4 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GETTalvez já em andamento @coughlmao assumiu hoje. Abertabug good first issue help wanted idempotency
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
aws-powertools/powertools-lambda-python#8727 · 4 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 secondsTalvez já em andamento @CJstate assumiu hoje. Abertabug good first issue help wanted idempotency
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
aws-powertools/powertools-lambda-python#8726 · 3 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashedTalvez já em andamento @Neeraj111010 assumiu hoje. Abertabug good first issue help wanted idempotency
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
aws-powertools/powertools-lambda-python#8725 · 4 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Bug: output_serializer=PydanticSerializer crashes at import under from __future__ import annotationsTalvez já em andamento @sumedh-aerram assumiu hoje. Abertabug good first issue help wanted idempotency
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
aws-powertools/powertools-lambda-python#8722 · 6 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
Todas as issues de aws-powertools/powertools-lambda-python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
sususweet/midea_auto_cloud#285 ·
Mantenedores costumam responder em até 1 dia
-
Short positive Table maxlen values produce oversized cellsTalvez já em andamento @Gambit-Checkmate assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 18 dias
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 68/100
MangasMango/bound-to-rot#41 · 1 comentário ·
-
breaking change
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
Word viper missingAberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 68/100
dwyl/english-words#244 ·