Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/common/prebuilt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ pub fn get_prebuilt<T>(
) -> PyResult<Option<T>> {
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"))?) {
Copy link
Contributor

@davidhewitt davidhewitt Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type_ != "model" will always be True for type == "dataclass", so I think the new boolean logic here is wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, seems like it is wrong on main as well, I'll fix it

return Ok(None);
}

Expand Down