fix(idempotency): serialize UUID and datetime fields in dataclass payloads - #8501
Conversation
…loads aws-powertools#8075 made _prepare_data dump Pydantic models with mode="json", but the dataclass branch still returned the raw dataclasses.asdict() output. A dataclass holding a UUID, date, time, datetime, plain Enum or path failed on every call with "Object of type UUID is not JSON serializable" while hashing the idempotency key. Convert those values to JSON safe ones after asdict(). Values json already encodes, including str and int enums, are left as they are, so keys for dataclasses that worked before don't change.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8501 +/- ##
========================================
Coverage 96.80% 96.80%
========================================
Files 310 310
Lines 15579 15594 +15
Branches 1358 1361 +3
========================================
+ Hits 15081 15096 +15
Misses 362 362
Partials 136 136 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks for catching this, @Om-singhaI! I pushed a follow-up that moves the conversion to the hashing step, after JMESPath evaluation. This preserves existing encodings, including Decimal-based enums, and lets expressions and custom functions keep working with the original types.
I also added regression tests to verify that existing records are reused without executing the function again.
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |



Issue number: closes #8500
Summary
Changes
Adds an encoder used only when generating idempotency key and payload validation hashes. It supports UUID, date, datetime, time, plain Enum, and path values while giving the existing encoder priority. This preserves existing representations, including enums based on Decimal.
Dataclass inputs still go through
dataclasses.asdict(). The additional conversions happen afterevent_key_jmespathandpayload_validation_jmespathare evaluated, so built-in and custom functions receive the original field types. Dictionary inputs use the same hash encoder. Response serialization is unchanged.User experience
A dataclass containing UUID or datetime fields currently fails while hashing the input, before the function runs. These inputs can now be processed and subsequent calls reuse the saved result.
Compatibility tests assert the exact DynamoDB keys and validation hashes for previously supported inputs, then return an existing record without executing the function. Additional tests cover replay with local caching enabled and disabled, changed-payload rejection, and unsupported types.
Validation
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.