Add tests to ensure a ValidationError is raised#9954
Add tests to ensure a ValidationError is raised#9954marielejeune wants to merge 1 commit intofastapi:masterfrom
Conversation
|
I would argue this is not a bug in pydantic but a misuse of a performance-oriented validation escape hatch. You should only use The reason this would have worked in earlier versions of FastAPI/pydantic was the use of the "secure cloned field", whose purpose was to prevent extra fields from being included at serialization time. But this came at the price of a massive performance overhead caused by revalidating data that in principle was already known to be valid. We made specific changes in pydantic v2 to render the secure cloned field unnecessary, in particular, serializing models based on their schema rather than through recursive calls to the field attributes' As a consequence, there are now issues with invalidly-constructed models not being validated properly, but again, I would consider this a misuse of |
|
Amazing writeup as always @dmontagu, thanks! And thanks @marielejeune, I think that would probably answer it, if you have more questions/problems, please create a new discussion question. 🤓 |
These tests were added to cover a new Response validation case.
Second tests fails as there is a bug in Pydantic v2.1.1.
See: