Skip to content

Commit b1a492a

Browse files
committed
fixed from_orm compatibility
1 parent da7b302 commit b1a492a

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

ninja/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Django Ninja - Fast Django REST framework"""
22

3-
__version__ = "1.0.0"
3+
__version__ = "1.0.1"
44

55

66
from pydantic import Field

ninja/schema.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class Config:
201201
def _run_root_validator(
202202
cls, values: Any, handler: ModelWrapValidatorHandler[S], info: ValidationInfo
203203
) -> Any:
204-
# when extra is "forbid" we need to perform default pydantic valudation
204+
# when extra is "forbid" we need to perform default pydantic validation
205205
# as DjangoGetter does not act as dict and pydantic will not be able to validate it
206206
if cls.model_config.get("extra") == "forbid":
207207
handler(values)
@@ -210,8 +210,8 @@ def _run_root_validator(
210210
return handler(values)
211211

212212
@classmethod
213-
def from_orm(cls: Type[S], obj: Any) -> S:
214-
return cls.model_validate(obj)
213+
def from_orm(cls: Type[S], obj: Any, **kw: Any) -> S:
214+
return cls.model_validate(obj, **kw)
215215

216216
def dict(self, *a: Any, **kw: Any) -> DictStrAny:
217217
"Backward compatibility with pydantic 1.x"

tests/test_schema_context.py

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def test_schema_with_context():
4949
obj = ResolveWithContext.model_validate({"value": 2}, context={"extra": 2})
5050
assert obj.value == 4
5151

52+
obj = ResolveWithContext.from_orm({"value": 2}, context={"extra": 2})
53+
assert obj.value == 4
54+
5255

5356
def test_request_context():
5457
resp = client.post("/resolve_ctx", json={})

0 commit comments

Comments
 (0)