-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adrf
(Async DRF) Support
#947
Comments
Hey John, On the topic: Regarding #931, I don't think it is really related. They used plain django (async) views. There is no structure around it to inspect. No "declared" parsers, renderes, serializers, pagination, etc. If "Off" the topic: It kind of feels like drf-spectacular again, which was declined to be integrated into DRF. It was the right decision at the end of the day, but I guess cohesive If I look over the fence at django-ninja or fastapi, I see fast frameworks with build-in async support as well as OpenAPI schema generation out of the box. We look a bit pale in comparison at the moment, don't you think? well that's my 2 cents. |
Completely understand/agree. I mostly wanted you to be aware of the DRF decision as soon as I learned about it so you were aware/prepared since
I agree with all of your sentiments. I asked this question to Tom and the response was:
My feeling is that DRF is a bit in maintence mode and the maintainers are delegating new features many would consider "core" in 2023 (OpenAPI 3 support, Async, etc.) to third party packages to reduce maintence burden. |
Thanks for letting me know. I'm sure we can figure out some solution to this.
I kind of agree with his statement there. It indeed keeps you flexible, but do you want 2 different async plugins for DRF like we have 2 OpenAPI plugins? That fragmentation is not good for essential features. Also, I don't think the design space is that large honestly. How many ways can this be implemented sensibly? Not that many I suppose. Also, not committing while others have async as core feature is not good look. As you rightly pointed out, it feels a bit like maintenance mode. Time will tell if people will vote with their feet. |
This is grossly misleading. Just adding support for The state in Django 4.2 is that we will have support for one async-capable database client ( There is also stuff around async signals (see here) and also |
Hello! I've been working on a Django REST Framework project using For my use case, I'm only using Here's an (extremely) contrived example: from adrf.viewsets import ViewSet as AsyncViewSet
from drf_spectacular.utils import extend_schema, extend_schema_view
from myproject.models.question import Question, QuestionDetail as QuestionDetailSerializer
class BaseViewSet(AsyncViewSet):
serializer_class = None
async def retrieve(self, request, *pos, **kw):
obj = await self.aget_object()
return Response(self.serializer_class(obj).data)
@extend_schema_view(
retrieve=extend_schema(responses={200: QuestionDetailSerializer})
)
class QuestionViewSet(BaseViewSet):
queryset = Question.objects.all()
serializer_class = QuestionDetailSerializer Trying to retrieve the details about a
Since methods are only(?) isolated when they're derived from a base class, this is the only use case that breaks. Defining The root of the problem is in def isolate_view_method(view, method_name):
...
@functools.wraps(method)
def wrapped_method(self, request, *args, **kwargs):
return method(self, request, *args, **kwargs)
...
return wrapped_method becomes this def isolate_view_method(view, method_name):
...
if inspect.iscoroutinefunction(method):
@functools.wraps(method)
async def wrapped_method(self, request, *args, **kwargs):
return await method(self, request, *args, **kwargs)
else:
@functools.wraps(method)
def wrapped_method(self, request, *args, **kwargs):
return method(self, request, *args, **kwargs)
...
return wrapped_method I'll see what I can do about adding test coverage for this fix and contributing it back as a PR. |
@zbmott is this the only failure with regards to @ngnpope yeah sorry, you are absolutely right. My statement was very optimistic with a good dose of wishful thinking. Django is not there yet, but at least it is moving in the right direction with a reasonable velocity imho. Even if Django is trying to stay on top of the state of the art, by declaring DRF maintenance only, it will create a growing functionality gap and thus devaluing the whole stack imho. |
Guys i need help i am having this error using adrf: RuntimeWarning: coroutine 'User_Serializer.create' was never awaited class User_Serializer(Serializer):
class User_Viewsets(ViewSet):
|
It was recently decided that the "official" async support for DRF would be the
adrf
package:Does
drf-spectacular
support this package? I didn't see it listed in the third party packages:It provides a new Async class-based and functional views. These allow end users to use
async
functionalities to better scale their DRF applications.Somewhat related to
The text was updated successfully, but these errors were encountered: