From 1dffec3dc428052b2f8311f83131298fc779ccc4 Mon Sep 17 00:00:00 2001 From: Simon Schoonjans Date: Fri, 29 Mar 2024 16:07:12 +0100 Subject: [PATCH] fix: catch pydantic panic exception when validating field with skip_validation context (#51) --- src/waylay/sdk/api/_models.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/waylay/sdk/api/_models.py b/src/waylay/sdk/api/_models.py index d39dedb..cc0b014 100644 --- a/src/waylay/sdk/api/_models.py +++ b/src/waylay/sdk/api/_models.py @@ -68,13 +68,17 @@ def _model_validator( raise for field_name in model.model_fields_set: field_value = getattr(model, field_name) - cls.__pydantic_validator__.validate_assignment( - model, - field_name, - field_value, - strict=(info.config or {}).get("strict"), - context=context, - ) + strict = (info.config or {}).get("strict") + try: + cls.__pydantic_validator__.validate_assignment( + model, + field_name, + field_value, + strict=strict, + context=context, + ) + except BaseException: + pass return model else: raise