Skip to content
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

About Async Relational Fields #11

Open
HappyDingning opened this issue Apr 16, 2023 · 1 comment
Open

About Async Relational Fields #11

HappyDingning opened this issue Apr 16, 2023 · 1 comment

Comments

@HappyDingning
Copy link

Defining relational fields in a serializer may incur additional database queries, but Django does not natively support asynchronous many-to-one or one-to-one queries. Django will report an error if you try to do many-to-one or one-to-one queries in an async context.

In fact, the best practice is to use select_related or prefetch_related to query all the data that needs to be used at once when defining the queryset, so as to avoid additional database queries in the future.

I want to try to implement a simple asynchronous serializer, but my confusion is that when the user does a many-to-one or one-to-one query and does not use select_related or prefetch_related, should Django report an error or take some way to achieve async many-to-one or one-to-one queries?

I would like to ask what is your take on this matter? Thank you.

@imgVOID
Copy link

imgVOID commented Oct 4, 2023

You can use psycopg.AsyncConnection
Django also has async support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants