Skip to content

Commit dec9fcd

Browse files
committed
Do not check for 'typed-dict' schemas for prebuilt validator/serializer
1 parent 164b9ff commit dec9fcd

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/common/prebuilt.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ pub fn get_prebuilt<T>(
1212
) -> PyResult<Option<T>> {
1313
let py = schema.py();
1414

15-
// we can only use prebuilt validators / serializers from models, typed dicts, and dataclasses
16-
// however, we don't want to use a prebuilt structure from dataclasses if we have a generic_origin
17-
// because the validator / serializer is cached on the unparametrized dataclass
18-
if !matches!(type_, "model" | "typed-dict")
19-
|| matches!(type_, "dataclass") && schema.contains(intern!(py, "generic_origin"))?
20-
{
15+
// we can only use prebuilt validators/serializers from models and Pydantic dataclasses.
16+
// However, we don't want to use a prebuilt structure from dataclasses if we have a `generic_origin`
17+
// as this means the dataclass was parametrized (so a generic alias instance), and `cls` in the
18+
// core schema is still the (unparametrized) class, meaning we would fetch the wrong validator/serializer.
19+
if !(type_ == "model") || (type_ == "dataclass" && schema.contains(intern!(py, "generic_origin"))?) {
2120
return Ok(None);
2221
}
2322

0 commit comments

Comments
 (0)