From 5e1a003dd3928e292a2ecbe8425bc802a43924e8 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Thu, 6 Feb 2025 10:48:23 +0100 Subject: [PATCH 1/2] Do not check for `'typed-dict'` schemas for prebuilt validator/serializer --- src/common/prebuilt.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/prebuilt.rs b/src/common/prebuilt.rs index 961123691..3212748cf 100644 --- a/src/common/prebuilt.rs +++ b/src/common/prebuilt.rs @@ -12,12 +12,11 @@ pub fn get_prebuilt( ) -> PyResult> { let py = schema.py(); - // we can only use prebuilt validators / serializers from models, typed dicts, and dataclasses - // however, we don't want to use a prebuilt structure from dataclasses if we have a generic_origin - // because the validator / serializer is cached on the unparametrized dataclass - if !matches!(type_, "model" | "typed-dict") - || matches!(type_, "dataclass") && schema.contains(intern!(py, "generic_origin"))? - { + // we can only use prebuilt validators/serializers from models and Pydantic dataclasses. + // However, we don't want to use a prebuilt structure from dataclasses if we have a `generic_origin` + // as this means the dataclass was parametrized (so a generic alias instance), and `cls` in the + // core schema is still the (unparametrized) class, meaning we would fetch the wrong validator/serializer. + if (type_ != "model") || (type_ == "dataclass" && schema.contains(intern!(py, "generic_origin"))?) { return Ok(None); } From 3059474aee46b80b5d69abee09c5625d99f1d5ce Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:13:57 +0100 Subject: [PATCH 2/2] Fix condition --- src/common/prebuilt.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/prebuilt.rs b/src/common/prebuilt.rs index 3212748cf..f4307064f 100644 --- a/src/common/prebuilt.rs +++ b/src/common/prebuilt.rs @@ -16,7 +16,9 @@ pub fn get_prebuilt( // However, we don't want to use a prebuilt structure from dataclasses if we have a `generic_origin` // as this means the dataclass was parametrized (so a generic alias instance), and `cls` in the // core schema is still the (unparametrized) class, meaning we would fetch the wrong validator/serializer. - if (type_ != "model") || (type_ == "dataclass" && schema.contains(intern!(py, "generic_origin"))?) { + if !matches!(type_, "model" | "dataclass") + || (type_ == "dataclass" && schema.contains(intern!(py, "generic_origin"))?) + { return Ok(None); }