Skip to content

Commit 0bbbdfa

Browse files
committed
add async_compute_route_parameters in RouteContext
1 parent a3d57dd commit 0bbbdfa

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ninja_extra/context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ def compute_route_parameters(
106106
self.kwargs.update({"view_func_kwargs": values}, **values)
107107
self._has_computed_route_parameters = True
108108

109+
async def async_compute_route_parameters(self) -> None:
110+
from asgiref.sync import sync_to_async
111+
112+
await sync_to_async(self.compute_route_parameters)()
113+
109114

110115
def get_route_execution_context(
111116
request: HttpRequest,

ninja_extra/operation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ async def _prep_run( # type:ignore
326326
ROUTE_CONTEXT_VAR.set(None)
327327

328328
async def run(self, request: HttpRequest, **kw: Any) -> HttpResponseBase: # type: ignore
329-
from asgiref.sync import sync_to_async
330329
try:
331330
async with self._prep_run(
332331
request,
@@ -344,7 +343,7 @@ async def run(self, request: HttpRequest, **kw: Any) -> HttpResponseBase: # typ
344343
await route_function.async_run_check_permissions(ctx) # type: ignore[attr-defined]
345344

346345
if not ctx.has_computed_route_parameters:
347-
await sync_to_async(ctx.compute_route_parameters)()
346+
await ctx.async_compute_route_parameters()
348347

349348
result = await self.view_func(request, **ctx.kwargs["view_func_kwargs"])
350349
assert ctx.response is not None

0 commit comments

Comments
 (0)