diff --git a/ninja/__init__.py b/ninja/__init__.py index 60a30938..9fa08662 100644 --- a/ninja/__init__.py +++ b/ninja/__init__.py @@ -1,6 +1,6 @@ """Django Ninja - Fast Django REST framework""" -__version__ = "1.0.0" +__version__ = "1.0.1" from pydantic import Field diff --git a/ninja/schema.py b/ninja/schema.py index 93279710..482a7fd5 100644 --- a/ninja/schema.py +++ b/ninja/schema.py @@ -201,7 +201,7 @@ class Config: def _run_root_validator( cls, values: Any, handler: ModelWrapValidatorHandler[S], info: ValidationInfo ) -> Any: - # when extra is "forbid" we need to perform default pydantic valudation + # when extra is "forbid" we need to perform default pydantic validation # as DjangoGetter does not act as dict and pydantic will not be able to validate it if cls.model_config.get("extra") == "forbid": handler(values) @@ -210,8 +210,8 @@ def _run_root_validator( return handler(values) @classmethod - def from_orm(cls: Type[S], obj: Any) -> S: - return cls.model_validate(obj) + def from_orm(cls: Type[S], obj: Any, **kw: Any) -> S: + return cls.model_validate(obj, **kw) def dict(self, *a: Any, **kw: Any) -> DictStrAny: "Backward compatibility with pydantic 1.x" diff --git a/tests/test_schema_context.py b/tests/test_schema_context.py index a282bfc7..b346986c 100644 --- a/tests/test_schema_context.py +++ b/tests/test_schema_context.py @@ -49,6 +49,9 @@ def test_schema_with_context(): obj = ResolveWithContext.model_validate({"value": 2}, context={"extra": 2}) assert obj.value == 4 + obj = ResolveWithContext.from_orm({"value": 2}, context={"extra": 2}) + assert obj.value == 4 + def test_request_context(): resp = client.post("/resolve_ctx", json={})