Bug: DataclassSerializer cannot save datetime/UUID fields and does not rebuild nested dataclasses on replay

Abierto
#8,723 5 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@Suraj1347 ya está trabajando en esto.

Desde el 1/11/2026.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
75/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

Read AGENTS.md for test commands. Edit aws_lambda_powertools/utilities/idempotency/serialization/dataclass.py: make to_dict emit ISO strings and str for UUID, and have from_dict rebuild nested dataclasses via dataclasses.fields(). Add tests in tests/functional/idempotency/_boto3/test_idempotency.py verifying round-trip of UUID/datetime and nested dataclass equality. Done when replayed value equals original.

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

DataclassSerializer saves a dataclass result that contains datetime or UUID fields, and rebuilds nested dataclasses on replay, so the replayed value equals the original.

Current Behaviour

to_dict returns dataclasses.asdict(data) unchanged and save_success dumps it with the plain JSON encoder, which has no datetime/UUID support, so the first call fails with IdempotencyPersistenceLayerError (and then hits the stuck INPROGRESS record described in the companion issue for item 4). This is the same class of bug fixed for Pydantic in #8569. Separately, from_dict does self.__model(**data), so nested dataclasses come back as plain dicts on replay.

Code snippet
import uuid
from dataclasses import dataclass
from datetime import datetime
from aws_lambda_powertools.utilities.idempotency import idempotent_function
from aws_lambda_powertools.utilities.idempotency.serialization.dataclass import DataclassSerializer

@dataclass
class Item:
    sku: str

@dataclass
class Order:
    id: uuid.UUID
    created: datetime
    item: Item

@idempotent_function(data_keyword_argument="order", persistence_store=layer, output_serializer=DataclassSerializer)
def process(order: dict) -> Order:
    return Order(id=uuid.uuid4(), created=datetime(2026, 1, 1), item=Item(sku="x"))

process(order={"id": 1})  # IdempotencyPersistenceLayerError: Object of type UUID is not JSON serializable
# with only str fields: first call Order(item=Item(sku='x')), replay Order(item={'sku': 'x'})
Possible Solution

In aws_lambda_powertools/utilities/idempotency/serialization/dataclass.py: make to_dict produce JSON-safe values (ISO strings for datetime/date, str for UUID), and in from_dict rebuild nested dataclasses from dataclasses.fields() type hints (and lists of them). Tests in tests/functional/idempotency/_boto3/test_idempotency.py: a dataclass with UUID and datetime round-trips through save and replay, and a nested dataclass comes back as the dataclass, not a dict.

Item 6 of the Idempotency audit in #8603. No AWS resources needed.

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 8 h
PR fusionados (30 d)
92

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.