From cb3a8ca0199c86e8190a76377506cbdcbef3c38c Mon Sep 17 00:00:00 2001 From: Pedro Lobato <69770518+Lob26@users.noreply.github.com> Date: Tue, 10 Feb 2026 09:52:05 -0500 Subject: [PATCH] Final fix so tests works nicely --- fastapi/encoders.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastapi/encoders.py b/fastapi/encoders.py index 453bd3556..879def72e 100644 --- a/fastapi/encoders.py +++ b/fastapi/encoders.py @@ -321,7 +321,9 @@ def jsonable_encoder( encoded_dict[encoded_key] = encoded_value return encoded_dict - if isinstance(obj, (Sequence, GeneratorType)): + # Note that we check for `Sequence` and not `list` because we want to support any kind of sequence, like `list`, `tuple`, `set`, etc. + # Also, we check that it's not a `bytes` object, because `bytes` is also a `Sequence`, but we want to rely on the TYPE_ENCODERS for `bytes` and avoid code duplication. + if isinstance(obj, (Sequence, GeneratorType)) and not isinstance(obj, bytes): encoded_list = [] for item in obj: encoded_list.append(