Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
nofalx committed Sep 9, 2023
1 parent 4177f58 commit 5474d2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
23 changes: 15 additions & 8 deletions ninja/operation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from typing import (TYPE_CHECKING, Any, Callable, Dict, Iterable, List,
Optional, Sequence, Type, Union, cast)
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Sequence,
Type,
Union,
cast,
)

import django
import pydantic
Expand Down Expand Up @@ -194,16 +205,12 @@ def _result_to_response(

resp_object = ResponseObject(result)
# ^ we need object because getter_dict seems work only with model_validate
result = response_model.model_validate(
resp_object
).model_dump(
result = response_model.model_validate(resp_object).model_dump(
by_alias=self.by_alias,
exclude_unset=self.exclude_unset,
exclude_defaults=self.exclude_defaults,
exclude_none=self.exclude_none,
)[
"response"
]
)["response"]
return self.api.create_response(
request, result, temporal_response=temporal_response
)
Expand Down
9 changes: 4 additions & 5 deletions ninja/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ def resolve_initials(self, obj):
from typing import Any, Callable, Dict, Type, TypeVar, Union, no_type_check

import pydantic
from django.db import models
from django.db.models import Manager, QuerySet
from django.db.models.fields.files import FieldFile
from django.template import Variable, VariableDoesNotExist
from pydantic import (BaseModel, Field, ValidationInfo, model_validator,
validator)
from pydantic import BaseModel, Field, ValidationInfo, model_validator, validator
from pydantic._internal._model_construction import ModelMetaclass
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue

Expand Down Expand Up @@ -204,9 +202,10 @@ class Config:
def _run_root_validator(
cls, values: Any, handler: Callable, info: ValidationInfo
) -> Any:

# 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)
through_model_validate = (
info and info.context and info.context.get("through_model_validate", False)
)
if not through_model_validate:
handler(values)

Expand Down

0 comments on commit 5474d2c

Please sign in to comment.