Skip to content

fix(idempotency): make DataclassSerializer save and replay non-JSON-native fields - #8904

Open
ibrhmyi wants to merge 2 commits into
aws-powertools:developfrom
ibrhmyi:fix/idempotency-dataclass-serializer
Open

ibrhmyi wants to merge 2 commits into
aws-powertools:developfrom
ibrhmyi:fix/idempotency-dataclass-serializer

Conversation

@ibrhmyi

@ibrhmyi ibrhmyi commented Nov 24, 2026 •

Copy link
Copy Markdown

Issue number: closes #8723

Summary

Changes

DataclassSerializer.to_dict returned dataclasses.asdict() unchanged, so a result holding datetime, UUID or Enum values failed to save with IdempotencyPersistenceLayerError and left the record INPROGRESS. from_dict also returned nested dataclasses as plain dicts on replay.

  • to_dict now dumps JSON-compatible values.
  • from_dict rebuilds datetime, date, time, UUID, Enum, Decimal and nested dataclasses (including inside lists, tuples, sets and dicts) from the field type hints.
  • Values that do not match the declared type are returned untouched, so records stored before this change replay as before.
  • Docs note added in docs/utilities/idempotency.md.

User experience

Before: returning a dataclass with a datetime/UUID/Enum field from an idempotent function raised on save; replayed results had nested dataclasses as dicts.
After: such results are saved and replayed as the original types.

Verification

  • New tests in tests/functional/idempotency/_boto3/test_idempotency_dataclass_serializer.py; one fails on develop without the fix and all pass with it.
  • pytest tests/functional/idempotency: 265 passed, 1 skipped.
  • ruff check, ruff format --check, and mypy on the changed module: clean.

An AI assistant (Claude Code) helped write this change; I reviewed it and ran the tests myself.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…ative fields

to_dict returned dataclasses.asdict() unchanged, so a result holding datetime, UUID or Enum values failed to save with IdempotencyPersistenceLayerError and left the record INPROGRESS. from_dict also returned nested dataclasses as plain dicts on replay.

Dump JSON-compatible values in to_dict, and rebuild datetime, date, time, UUID, Enum, Decimal and nested dataclasses (including inside lists, tuples, sets and dicts) in from_dict from the field type hints. Values that do not match the declared type are returned untouched, so records stored before this change replay as before.

closes aws-powertools#8723
@ibrhmyi
ibrhmyi requested a review from a team as a code owner November 24, 2026 21:14
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation tests labels Nov 24, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 24, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

documentation Improvements or additions to documentation size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant