Skip to content

Commit dcf0cde

Browse files
committed
fix _run_authentication creating the coroutine result twice
1 parent 4a51ecf commit dcf0cde

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ninja/operation.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def __init__(
8181
self.throttle_objects: List[BaseThrottle] = []
8282
if throttle is not NOT_SET:
8383
for th in throttle: # type: ignore
84-
assert isinstance(
85-
th, BaseThrottle
86-
), "Throttle should be an instance of BaseThrottle"
84+
assert isinstance(th, BaseThrottle), (
85+
"Throttle should be an instance of BaseThrottle"
86+
)
8787
self.throttle_objects.append(th)
8888

8989
self.signature = ViewSignature(self.path, self.view_func)
@@ -163,9 +163,9 @@ def set_api_instance(self, api: "NinjaAPI", router: "Router") -> None:
163163
if router.throttle != NOT_SET:
164164
_t = router.throttle
165165
self.throttle_objects = isinstance(_t, BaseThrottle) and [_t] or _t # type: ignore
166-
assert all(
167-
isinstance(th, BaseThrottle) for th in self.throttle_objects
168-
), "Throttle should be an instance of BaseThrottle"
166+
assert all(isinstance(th, BaseThrottle) for th in self.throttle_objects), (
167+
"Throttle should be an instance of BaseThrottle"
168+
)
169169

170170
if self.tags is None:
171171
if router.tags is not None:
@@ -207,7 +207,11 @@ def _run_authentication(self, request: HttpRequest) -> Optional[HttpResponse]:
207207
if is_async_callable(callback) or getattr(callback, "is_async", False):
208208
result = callback(request)
209209
if inspect.iscoroutine(result):
210-
result = async_to_sync(callback)(request)
210+
211+
async def await_result(cor):
212+
return await cor
213+
214+
result = async_to_sync(await_result)(result)
211215
else:
212216
result = callback(request)
213217
except Exception as exc:

0 commit comments

Comments
 (0)