vitalik / django-ninja

💨 Fast, Async-ready, Openapi, type hints based framework for building APIs
https://django-ninja.dev
MIT License
7.28k stars 432 forks source link

Fix `SynchronousOnlyOperation` error if `@paginate` with async view returns Django queryset #1293

Open qodot opened 2 months ago

qodot commented 2 months ago

When applying the paginate decorator to an async view that returns a Django queryset, a SynchronousOnlyOperation error occurs. (cause of https://github.com/vitalik/django-ninja/blob/457c066c82eb30203aab1e0d3c6b7c46befd2996/ninja/pagination.py#L206-L208)

To resolve this, I've added _inject_async_pagination within the paginate and RouterPaginated and differentiated the behavior based on the view type.