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

Abierto Apto para principiantes
#8,724 3 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@sumedh-aerram ya está trabajando en esto.

Desde el 1/11/2026.

  • #8739 de @sumedh-aerram — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
90/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
aws, python
Área
databases

Línea de trabajo

Lee aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py, centrándote en _item_to_data_record. Cambia idempotency_key para usar sort_key_attr cuando esté definido. Añade tests usando botocore.stub.Stubber en el cliente de la capa con sort_key_attr y un response_hook para verificar la clave, además de un test de acierto de caché local. Hecho cuando los nuevos tests pasan y la clave refleja el valor de ordenación.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
3.3k
Forks
511
Merge medio
3 d 4 h
PR fusionados (30 d)
98

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de aws-powertools/powertools-lambda-python

Todos los issues de aws-powertools/powertools-lambda-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.