From a28ffc95443adf53ce03625b689b6b7f4d2eb4e8 Mon Sep 17 00:00:00 2001 From: Ahmad Nofal Date: Fri, 8 Sep 2023 19:58:39 +0400 Subject: [PATCH] done all fixes --- ninja/schema.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ninja/schema.py b/ninja/schema.py index e8a7f3528..c7f8b7ace 100644 --- a/ninja/schema.py +++ b/ninja/schema.py @@ -204,14 +204,16 @@ class Config: def _run_root_validator( cls, values: Any, handler: Callable, info: ValidationInfo ) -> Any: - print(info) - # we perform 'before' validations only if - is_dict = bool( - info and info.context and info.context.get("is_dict", False) - ) - if not is_dict : + + # We dont perform 'before' validations if an validating through 'model_validate' + through_model_validate = info and info.context and info.context.get("through_model_validate", False) + if not through_model_validate: handler(values) + + # We add our DjangoGetter for the Schema values = DjangoGetter(values, cls, info.context) + + # To update the schema with our DjangoGetter return handler(values) @classmethod @@ -228,8 +230,7 @@ def model_validate( context: dict[str, Any] | None = None, ) -> BaseModel: context = context or {} - if not isinstance(obj, dict): - context = {"is_dict": True} + context["through_model_validate"] = True return super().model_validate( obj, *args, strict=strict, from_attributes=from_attributes, context=context )