Skip to content

Commit

Permalink
sometimes ruff makes me so bored
Browse files Browse the repository at this point in the history
  • Loading branch information
c4ffein committed Aug 20, 2024
1 parent b403d48 commit 9b385d9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ninja/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
try:
from asgiref.sync import sync_to_async
except ModuleNotFoundError:
pass
sync_to_async = None

if TYPE_CHECKING:
from ninja import NinjaAPI, Router # pragma: no cover
Expand Down Expand Up @@ -466,6 +466,9 @@ def get_view(self) -> Callable:
HttpResponseNotAllowed(allowed_methods, content=b"Method not allowed"),
)

if is_async:
assert sync_to_async # Ensure we fail here and not in view

def sync_view(request: HttpRequest, *a: Any, **kw: Any) -> HttpResponseBase:
operation = next(
(op for op in operations if request.method in op.methods), None
Expand All @@ -490,8 +493,6 @@ async def async_view(
return await cast(AsyncOperation, operation).run(request, *a, **kw)
return await sync_to_async(operation.run)(request, *a, **kw)

if is_async:
sync_to_async # Ensure we fail here and not in view
view = async_view if is_async else sync_view
view.csrf_exempt = True # type: ignore
if self.url_name:
Expand Down

0 comments on commit 9b385d9

Please sign in to comment.