Skip to content

Commit

Permalink
done all fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nofalx committed Sep 9, 2023
1 parent 1f929b0 commit 4177f58
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ninja/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand Down

0 comments on commit 4177f58

Please sign in to comment.