Convert class based views with async_to_sync

Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com>
Co-authored-by: Kevin Yang <kkaiyang94@users.noreply.github.com>
Co-authored-by: Katherine Kelly <kat-star@users.noreply.github.com>
This commit is contained in:
Tim Pansino 2021-06-03 14:10:58 -07:00
parent 60e3d34d19
commit 01c56e0947

View file

@ -1,6 +1,7 @@
import typing as t
from .globals import request
from .helpers import ensure_sync
from .typing import ResponseReturnValue
@ -80,7 +81,7 @@ class View:
def view(*args: t.Any, **kwargs: t.Any) -> ResponseReturnValue:
self = view.view_class(*class_args, **class_kwargs) # type: ignore
return self.dispatch_request(*args, **kwargs)
return ensure_sync(self.dispatch_request)(*args, **kwargs)
if cls.decorators:
view.__name__ = name
@ -154,4 +155,4 @@ class MethodView(View, metaclass=MethodViewType):
meth = getattr(self, "get", None)
assert meth is not None, f"Unimplemented method {request.method!r}"
return meth(*args, **kwargs)
return ensure_sync(meth)(*args, **kwargs)