From cfa38a0b6cf018fb7533537318b7bb6c2382da65 Mon Sep 17 00:00:00 2001 From: Charles Duffy Date: Tue, 29 Oct 2024 15:23:56 -0500 Subject: [PATCH] feat(Pydantic): honor hide_input_in_errors in throwing validation exceptions --- litestar/contrib/pydantic/pydantic_init_plugin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/litestar/contrib/pydantic/pydantic_init_plugin.py b/litestar/contrib/pydantic/pydantic_init_plugin.py index 0ca368453e..e8623d7809 100644 --- a/litestar/contrib/pydantic/pydantic_init_plugin.py +++ b/litestar/contrib/pydantic/pydantic_init_plugin.py @@ -51,7 +51,12 @@ def _dec_pydantic_v2(model_type: type[pydantic_v2.BaseModel], value: Any, strict try: return model_type.model_validate(value, strict=strict) except pydantic_v2.ValidationError as e: - raise ExtendedMsgSpecValidationError(errors=cast("list[dict[str, Any]]", e.errors())) from e + hide_input = False + if isinstance(model_config := getattr(model_type, "model_config", None), dict): + hide_input = bool(model_config.get("hide_input_in_errors")) + raise ExtendedMsgSpecValidationError( + errors=cast("list[dict[str, Any]]", e.errors(include_input=not hide_input)) + ) from e def _dec_pydantic_uuid(