Open TiansuYu opened 1 month ago
@TiansuYu,
This seems reasonable - let's move this to pydantic-core
- hopefully we could just remove the @final
decorator.
Related to https://github.com/pydantic/pydantic/issues/9686, can probably be done at the same time.
Initial Checks
Description
I would like to subclass the
pydantic_core.PydanticCustomError
such that each time a specificfield_validator
fails, it can raise aMySpecificError
instead of the normal pydantic ones.Currently,
PydanticCustomerError
is marked as@final
and as such, subclassing will lead toTypeError: type 'pydantic_core._pydantic_core.PydanticCustomError' is not an acceptable base type
.Futhermore, I have specific needs to do downstream error handling based on
MyTypeAError(PydanticCustomError)
andMyTypeBError(PydanticCustomError)
. Currently, this is not possible.I know workarounds would be wrap around the model creation step
Model(field_a=xxx, field_b=xxx)
with a catch block, but still, I do not want to involve my lib user to accept this complicated user experience.Please let me know:
BaseModel.__init__
).Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM mode