Open HorusTheSonOfOsiris opened 4 months ago
I am raising two issues together because they are somewhat interrelated. For Issue 2 where SerializationException is encountered. I believe that can be resolved by changing the convert_validation_error
method
def convert_validation_error(validation_error: ValidationErrorV1 | ValidationErrorV2) -> list[dict[str, Any]]:
error_list = validation_error.errors()
for error in error_list:
if isinstance(exception := error.get("ctx", {}).get("error"), Exception):
error["ctx"]["error"] = type(exception).__name__
return error_list # type: ignore[return-value]
We can change to following code:
def convert_validation_error(validation_error: ValidationErrorV1 | ValidationErrorV2) -> list[dict[str, Any]]:
error_list = json.loads(validation_error.json())
for error in error_list:
if isinstance(exception := error.get("ctx", {}).get("error"), Exception):
error["ctx"]["error"] = type(exception).__name__
return error_list # type: ignore[return-value]
This way Pydantic handle the nested model conversion.
Description
The DTOData class works as expected when there isn't a nested model. Based on the documentation, the idea of DTOData class is to delay the validation until
create_instance
method is called.This is working as expected for the first level model but calls Pydantic validation on nested models.
Second issue: I am facing an issue when overriding the
ValidationException
class. I am using an extra field in the error response which is not serialised properly. An internal error is raised:URL to code causing the issue
No response
MCVE
Steps to reproduce
For Issue: 1
exception_handlers
from app.For Issue 2:
ValidationException
in the app.Call /test endpoint with following data:
Screenshots
Logs
No response
Litestar Version
2.9.0final0
Platform