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

chore: Refactor async pagination #1340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Amr-elwetaidy
Copy link

Async Paginator

The evaluate AsyncGenerator causes:

django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async

This part of the code is the reason:
Screenshot_1

In fact, it's unnecessary at all as django already handles the queryset and evaluates it as an AsyncGenerator once you call it with async for


Similarly with the count() and acount() methods, you can directly call them on the queryset and no need to call all() first.

Screenshot_2

- Removed unnecessary async evaluation
- Removed unnecessary .all() when counting queryset
@vitalik
Copy link
Owner

vitalik commented Nov 19, 2024

I think .all there used to foce method that does not exist in a list

SCR-20241119-jvcn

@Amr-elwetaidy
Copy link
Author

I think .all there used to foce method that does not exist in a list

SCR-20241119-jvcn

I missed that one, but still why not use if not isinstance(queryset, list): ...

@Amr-elwetaidy
Copy link
Author

Anyway, The important one is the async, I had to override the class to get it working.

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

Successfully merging this pull request may close these issues.

2 participants