I have recently been using FASTAPI and Pydantic.
I would like to know the path to use to create a pydantic model without any validation.
I could see that there was the construct() method, however, this method still calls the personal validation methods created using @validator
Example of my code:
class Feedback(BaseModel):
rating: int
comment: str
date: datetime.date
@validator('rating')
def rating_validator(cls, rating):
if rating > 5 or rating < 0:
raise ValueError('value is not a valid rating')
return rating
@validator('date')
def date_validator(cls, date):
if date != datetime.date.today():
raise ValueError('value is not a valid date')
return date
In this example, the date validator allows when creating a feedback, checked if the date corresponds to that of the day, but when I want to return this value, later, when it comes from my DB, the validation necessarily leads to the error since it is to return to a different day.
So, I would like to succeed in using this model, without the validation.