Saurabh Vijay Salve
13 hours ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
6 additions and
1 deletions
-
fastapi/encoders.py
-
tests/test_jsonable_encoder.py
|
|
|
@ -82,7 +82,7 @@ def decimal_encoder(dec_value: Decimal) -> int | float: |
|
|
|
|
|
|
|
|
|
|
|
ENCODERS_BY_TYPE: dict[type[Any], Callable[[Any], Any]] = { |
|
|
|
bytes: lambda o: o.decode(), |
|
|
|
bytes: lambda o: o.decode(errors="replace"), |
|
|
|
Color: str, |
|
|
|
PyExtraColor: str, |
|
|
|
datetime.date: isoformat, |
|
|
|
|
|
|
|
@ -299,6 +299,11 @@ def test_decimal_encoder_infinity(): |
|
|
|
assert isinf(jsonable_encoder(data)["value"]) |
|
|
|
|
|
|
|
|
|
|
|
def test_encode_bytes_with_invalid_utf8_does_not_raise(): |
|
|
|
data = {"value": b"\xff"} |
|
|
|
assert jsonable_encoder(data) == {"value": "\ufffd"} |
|
|
|
|
|
|
|
|
|
|
|
def test_encode_deque_encodes_child_models(): |
|
|
|
class Model(BaseModel): |
|
|
|
test: str |
|
|
|
|