Skip to content

Commit 498e60a

Browse files
Customer must handle serialization on Pydantic models
1 parent bff9b81 commit 498e60a

File tree

3 files changed

+2
-29
lines changed

3 files changed

+2
-29
lines changed

aws_lambda_powertools/event_handler/openapi/encoders.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def jsonable_encoder( # noqa: PLR0911
8181
exclude_unset=exclude_unset,
8282
exclude_none=exclude_none,
8383
exclude_defaults=exclude_defaults,
84-
custom_serializer=custom_serializer,
8584
)
8685

8786
# Dataclasses
@@ -174,7 +173,6 @@ def _dump_base_model(
174173
exclude_unset: bool = False,
175174
exclude_none: bool = False,
176175
exclude_defaults: bool = False,
177-
custom_serializer: Optional[Callable[[Any], str]] = None,
178176
):
179177
"""
180178
Dump a BaseModel object to a dict, using the same parameters as jsonable_encoder
@@ -196,7 +194,6 @@ def _dump_base_model(
196194
obj_dict,
197195
exclude_none=exclude_none,
198196
exclude_defaults=exclude_defaults,
199-
custom_serializer=custom_serializer,
200197
)
201198

202199

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test_with_aws_encryption_sdk_as_required_package(session: nox.Session):
148148

149149

150150
@nox.session()
151-
@nox.parametrize("pydantic", ["1.10", "2.0"])
151+
@nox.parametrize("pydantic", ["1.10,<2.0", "2.0"])
152152
def test_with_pydantic_required_package(session: nox.Session, pydantic: str):
153153
"""Tests that only depends for Pydantic library v1 and v2"""
154154
# Event Handler OpenAPI

tests/functional/event_handler/_pydantic/test_openapi_encoders.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List
44

55
import pytest
6-
from pydantic import BaseModel, ConfigDict
6+
from pydantic import BaseModel
77
from pydantic.color import Color
88

99
from aws_lambda_powertools.event_handler.openapi.encoders import jsonable_encoder
@@ -230,30 +230,6 @@ def serializer(value):
230230
assert result == ["serialized"]
231231

232232

233-
@pytest.mark.usefixtures("pydanticv2_only")
234-
def test_openapi_encode_custom_serializer_pydantic():
235-
# GIVEN a sequence with a custom class
236-
class CustomClass:
237-
__slots__ = []
238-
239-
class Order(BaseModel):
240-
kind: CustomClass
241-
242-
model_config = ConfigDict(arbitrary_types_allowed=True)
243-
244-
order = Order(kind=CustomClass())
245-
246-
# AND a custom serializer
247-
def serializer(value):
248-
return "serialized"
249-
250-
# WHEN we call jsonable_encoder with the nested dictionary and unserializable value
251-
result = jsonable_encoder(order, custom_serializer=serializer)
252-
253-
# THEN we should get the custom serializer output
254-
assert result == {"kind": "serialized"}
255-
256-
257233
def test_openapi_encode_custom_serializer_dataclasses():
258234
# GIVEN a sequence with a custom class
259235
class CustomClass:

0 commit comments

Comments
 (0)