Accessing original object (one being serialized / validated) from validators, computed_field(), etc
I use pydantic in a FastAPI project to serialize SQLAlchemy entity objects, and I need to access the original entity object in @computed_field
methods and validators in order to access data from relationships (which are not supposed to be themselves serialized).
Accessing original object (one being serialized / validated) from validators, computed_field(), etc
I use pydantic in a FastAPI project to serialize SQLAlchemy entity objects, and I need to access the original entity object in @computed_field
methods and validators in order to access data from relationships (which are not supposed to be themselves serialized).
Why does my Pydantic model contain an extra attribute when popupated from an object with extra=ignore?
The title says it all:
is it possible to get dict of fields with FieldInfo from pydantic dataclass?
When creating classs by inheriting from BaseModel I can use model_fields property to get dict of field names and FieldInfo but how can I do it if I use Pydantic dataclass decorator instead of BaseModel?
How to create custom Pydantic type for Python’s “ElementTree”
I want to create a custom Pydantic type for Python’s ElementTree
. It should accept string as input and type to parse the XML string via ElementTree.fromstring
and raise appropriate error is invalid XML is found.
skip_on_failure Flag with Pydantic V2?
The root_validator
that was available with Pydantic V1 allowed a flag called skip_on_failure
, which allowed other validators to be run even if prior ones failed (when set to True
).
How do I get the model type inside a PydanticBaseSettingsSource?
I’m writing a custom PydanticBaseSettingsSource and processing fields of a specific type MyModel
How to restrict Pydantic URL validation to specific hosts or websites
I’m currently working with Pydantic’s URL type for URL validation in my Python project. However, it seems that Pydantic does not currently provide a built-in mechanism for this. So what is the best approach to restrict a URL to a specific list of hosts in Pydantic?
Need help in pydantic class output
how to solve this pydantic validation issue?
Pydantic: parsing a string into a complex object
I have several string fields: