From ec1d7547fdfe779245034ff163dadcb7928c520e Mon Sep 17 00:00:00 2001 From: enrico Date: Mon, 19 Sep 2022 07:12:01 -0400 Subject: [PATCH] Fix for missing await and using getattr instead of hasattr --- rest_framework/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rest_framework/views.py b/rest_framework/views.py index 180fdfd29..ec907531b 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -525,7 +525,7 @@ class APIView(View): self.headers = self.default_response_headers # deprecate? try: - sync_to_async(self.initial)(request, *args, **kwargs) + await sync_to_async(self.initial)(request, *args, **kwargs) # Get the appropriate handler method if request.method.lower() in self.http_method_names: @@ -547,7 +547,7 @@ class APIView(View): Dispatch checks if the view is async or not and uses the respective async or sync dispatch method. """ - if hasattr(self, 'view_is_async') and self.view_is_async: + if getattr(self, 'view_is_async', False): return self.async_dispatch(request, *args, **kwargs) else: return self.sync_dispatch(request, *args, **kwargs) @@ -562,7 +562,7 @@ class APIView(View): data = self.metadata_class().determine_metadata(request, self) return Response(data, status=status.HTTP_200_OK) - if hasattr(self, 'view_is_async') and self.view_is_async: + if getattr(self, 'view_is_async', False): async def handler(): return func() else: