Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ninja/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ def _run_authentication(self, request: HttpRequest) -> Optional[HttpResponse]:
if is_async_callable(callback) or getattr(callback, "is_async", False):
result = callback(request)
if inspect.iscoroutine(result):
result = async_to_sync(callback)(request)

async def await_result(cor: Coroutine) -> Any:
return await cor

result = async_to_sync(await_result)(result)
else:
result = callback(request)
Comment on lines 207 to 216
Copy link

@matez0 matez0 May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the try block,

                result = callback(request)
                if inspect.iscoroutine(result):
                    async def await_result(cor: Coroutine) -> Any:
                        return await cor

                    result = async_to_sync(await_result)(result)

would not be enough since result is created the same way in all cases and we may want to await result independently of the properties of callback?

except Exception as exc:
Expand Down