Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws_lambda_powertools/utilities/idempotency/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _prepare_data(data: Any) -> Any:

# Convert from Pydantic model
if callable(getattr(data, "model_dump", None)):
return data.model_dump()
return data.model_dump(mode="json")

# Convert from event source data class
if callable(getattr(data, "dict", None)):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional
from uuid import UUID

import pytest
from pydantic import BaseModel
Expand Down Expand Up @@ -194,6 +195,19 @@ class Foo(BaseModel):
assert as_dict == expected_result


def test_idempotent_function_pydantic_uuid():
# Scenario _prepare_data should convert a pydantic model with UUIDs to a dict
# with serialization of UUIDs to strings
class Foo(BaseModel):
uuid: UUID

uuid = UUID("01234567-0123-0123-0123-0123456789ab")
expected_result = {"uuid": str(uuid)}
data = Foo(uuid=uuid)
as_dict = _prepare_data(data)
assert as_dict == expected_result


@pytest.mark.parametrize("data", [None, "foo", ["foo"], 1, True, {}])
def test_idempotent_function_other(data):
# All other data types should be left as is
Expand Down