You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When annotating the request parameter of a route (in order to type request.auth) that has been decorated with @paginate the django server crashes with the following exception:
File "/app/.venv/lib/python3.10/site-packages/ninja/router.py", line 268, in decorator
self.add_api_operation(
File "/app/.venv/lib/python3.10/site-packages/ninja/router.py", line 319, in add_api_operation
path_view.add_operation(
File "/app/.venv/lib/python3.10/site-packages/ninja/operation.py", line 426, in add_operation
operation = OperationClass(
File "/app/.venv/lib/python3.10/site-packages/ninja/operation.py", line 82, in __init__
self.signature = ViewSignature(self.path, self.view_func)
File "/app/.venv/lib/python3.10/site-packages/ninja/signature/details.py", line 48, in __init__
self.signature = get_typed_signature(self.view_func)
File "/app/.venv/lib/python3.10/site-packages/ninja/signature/utils.py", line 38, in get_typed_signature
typed_params = [
File "/app/.venv/lib/python3.10/site-packages/ninja/signature/utils.py", line 43, in <listcomp>
annotation=get_typed_annotation(param, globalns),
File "/app/.venv/lib/python3.10/site-packages/ninja/signature/utils.py", line 54, in get_typed_annotation
annotation = make_forwardref(annotation, globalns)
File "/app/.venv/lib/python3.10/site-packages/ninja/signature/utils.py", line 60, in make_forwardref
return evaluate_forwardref(forward_ref, globalns, globalns)
File "/app/.venv/lib/python3.10/site-packages/ninja/signature/utils.py", line 20, in evaluate_forwardref
return cast(Any, type_)._evaluate(globalns, localns, recursive_guard=set())
File "/home/app/.local/share/uv/python/cpython-3.10.8-linux-x86_64-gnu/lib/python3.10/typing.py", line 694, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
NameError: name 'AuthenticatedNinjaRequest' is not defined
This can be reproduced with the following minimal route:
If the pagination decorator is removed, no crash occurs and everything works as expected.
Potential remedy
The crashing can be fixed by patching the function get_typed_signature at ninja/signature/utils.py with:
defget_typed_signature(call: Callable[..., Any]) ->inspect.Signature:
"Finds call signature and resolves all forwardrefs"signature=inspect.signature(call)
globalns=getattr(call, "__globals__", {})
typed_params= [
inspect.Parameter(
name=param.name,
kind=param.kind,
default=param.default,
annotation=get_typed_annotation(param, globalns),
)
# NOTE: the following line has been changed below# vvvvvvvvvvvvvvvvvvvvvvvvvvforparaminsignature.parameters.values() ifparam.name!="request"
]
typed_signature=inspect.Signature(typed_params)
returntyped_signature
But I'm not certain if this is a good solution. I can submit the above patch as a PR if you think it is sufficient, or if you have some other approach in mind I can try that too.
The only somewhat related issue/PR I could find: #1026
Versions (please complete the following information):
Python version: 3.10.8
Django version: 5.1.3
Django-Ninja version: 1.3.0
Pydantic version: 2.9.1
The text was updated successfully, but these errors were encountered:
Describe the bug
When annotating the
request
parameter of a route (in order to typerequest.auth
) that has been decorated with@paginate
the django server crashes with the following exception:This can be reproduced with the following minimal route:
If the pagination decorator is removed, no crash occurs and everything works as expected.
Potential remedy
The crashing can be fixed by patching the function
get_typed_signature
atninja/signature/utils.py
with:But I'm not certain if this is a good solution. I can submit the above patch as a PR if you think it is sufficient, or if you have some other approach in mind I can try that too.
The only somewhat related issue/PR I could find: #1026
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: