Skip to content

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

Open

Description

@leandrodamascena

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

Activity

  1. added this to the 3.41.0 milestone on Oct 31, 2026
  2. powertools-for-aws-oss-automation commented on Oct 31, 2026

    @powertools-for-aws-oss-automation

    Note

    For those interested in contributing, please leave a comment below so that we can assign the issue to you and make sure we don't duplicate efforts. If you have any further questions, please don't hesitate to ask below or on our Discord server.

  3. leandrodamascena commented on Oct 31, 2026

    @leandrodamascena
    ContributorAuthor

    @Suraj1347 you asked for this one in #8603 first, so it's yours. Take your time, it goes into 3.41.0. The two parts (JSON-safe to_dict and rebuilding nested dataclasses in from_dict) can be one PR.

  4. leandrodamascena commented on Nov 1, 2026

    @leandrodamascena
    ContributorAuthor

    @Suraj1347 GitHub won't let me assign you until you comment here, since you only commented on the discussion. Drop a line below and I'll assign it right away.

  5. Suraj1347 commented on Nov 1, 2026

    @Suraj1347
    Contributor

    Thanks, @leandrodamascena! I appreciate you reserving this issue for me.

    I'll take ownership of this issue and work on both JSON-safe serialization and rebuilding nested dataclasses during deserialization in a single PR.

    I'll first review AGENTS.md and the existing serializer implementation, along with the related Pydantic fix. I'll add appropriate regression tests and report the verification results accurately.

    Thanks for the opportunity!

  6. Suraj1347 commented on Nov 1, 2026

    @Suraj1347
    Contributor

    Hi @leandrodamascena,

    The implementation for issue #8723 is complete locally.

    I have added regression tests covering UUID, datetime, date serialization, nested dataclass reconstruction, lists, Optional fields and typed dictionaries.

    The Idempotency unit and functional test suites passed (219 tests), along with Ruff checks, formatting, targeted mypy and documentation build.

    I currently don't have AWS credentials available, so I cannot perform real DynamoDB verification locally. The issue mentions that no AWS resources are needed.

    Would the existing public-API functional tests and CI verification be sufficient for this contribution?

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomershelp wantedCould use a second pair of eyes/handsidempotencyIdempotency utility

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions