From c5454038d5d8795ddee95bee8085972530c08f3f Mon Sep 17 00:00:00 2001 From: Ben Brady Date: Sat, 9 Aug 2025 02:55:00 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20tweaked=20encoder=20primative=20?= =?UTF-8?q?key=20skip=20to=20disallow=20subclasses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/encoders.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastapi/encoders.py b/fastapi/encoders.py index b43d372d2..41c589d49 100644 --- a/fastapi/encoders.py +++ b/fastapi/encoders.py @@ -375,7 +375,9 @@ def encode_dict( if key not in allowed_keys: continue - if isinstance(key, primitive_types): + # use type() in, instead of isinstance + # we don't want to allow subclasses, they should be encoded still + if type(key) in primitive_types: encoded_key = key else: encoded_key = encode_value(