From 9266fe33578fefe6b727242f805d4fdf8ec48837 Mon Sep 17 00:00:00 2001 From: Ben Brady Date: Thu, 21 Aug 2025 23:14:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20moved=20encode=5Fdict=20check=20?= =?UTF-8?q?allowed=5Fkeys=20to=20be=20first?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/encoders.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastapi/encoders.py b/fastapi/encoders.py index df6990089..851fdc3ee 100644 --- a/fastapi/encoders.py +++ b/fastapi/encoders.py @@ -369,12 +369,13 @@ def encode_dict( allowed_keys -= set(exclude) for key, value in obj.items(): - if sqlalchemy_safe and isinstance(key, str) and key.startswith("_sa"): + if key not in allowed_keys: continue if value is None and exclude_none: continue - if key not in allowed_keys: + if sqlalchemy_safe and isinstance(key, str) and key.startswith("_sa"): continue + encoded_key = encode_value( key, by_alias=by_alias,