Skip to content

Using apaginate_queryset when the paginator is AsyncPaginationBase #264

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

Merged

Conversation

Aidan79225
Copy link
Contributor

@Aidan79225 Aidan79225 commented May 2, 2025

This diff introduces support for both synchronous and asynchronous pagination in the PaginatorOperation class in the ninja_extra/pagination/operations.py file. The key changes include:

  1. Import Updates:

    • Added AsyncPaginationBase to the imports from ninja.pagination, alongside the existing PaginationBase.
  2. Paginator Type Update:

    • The paginator parameter in the PaginatorOperation class's constructor is updated to accept either PaginationBase or AsyncPaginationBase using Union.
  3. Asynchronous Pagination Logic:

    • In the as_view method, the logic for handling pagination is updated to check the type of the paginator.
      • If the paginator is of type AsyncPaginationBase, its apaginate_queryset method is used.
      • Otherwise, the existing synchronous method (paginate_queryset) is wrapped with sync_to_async.

These changes enable the PaginatorOperation class to handle both synchronous and asynchronous pagination seamlessly, improving flexibility for developers using the library.

@codecov-commenter
Copy link

codecov-commenter commented May 3, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.01%. Comparing base (3b48be2) to head (f0d6a18).
Report is 55 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #264      +/-   ##
==========================================
- Coverage   99.45%   98.01%   -1.44%     
==========================================
  Files          56       68      +12     
  Lines        2552     2770     +218     
==========================================
+ Hits         2538     2715     +177     
- Misses         14       55      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Aidan79225 Aidan79225 force-pushed the feature/support-real-async-paginator branch from 64c8353 to 9207cc5 Compare May 3, 2025 10:07
@Aidan79225
Copy link
Contributor Author

Fix and updated

@eadwinCode eadwinCode self-requested a review May 4, 2025 06:42
eadwinCode
eadwinCode previously approved these changes May 4, 2025
@eadwinCode eadwinCode dismissed their stale review May 4, 2025 06:46

I cant trigger CI Action on this PR

@Aidan79225 Aidan79225 force-pushed the feature/support-real-async-paginator branch from 9207cc5 to bfa8cba Compare May 4, 2025 09:07
@Aidan79225
Copy link
Contributor Author

Aidan79225 commented May 4, 2025

I rebased, @eadwinCode could you try to trigger CI actions again

@eadwinCode
Copy link
Owner

Thanks for working on this @Aidan79225

@Aidan79225
Copy link
Contributor Author

@eadwinCode It seems django isn't supported async orm before version-4.2, I updated with a commit for this cases

@eadwinCode
Copy link
Owner

@eadwinCode It seems django isn't supported async orm before version-4.2, I updated with a commit for this cases

Yes, thats correct

@eadwinCode eadwinCode merged commit a3c5e65 into eadwinCode:master May 4, 2025
23 checks passed
@Aidan79225 Aidan79225 deleted the feature/support-real-async-paginator branch May 5, 2025 03:22
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.

3 participants