-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Paginators always repeat the query even if the count is 0 #4201
Comments
Do you have an analysis in regard to where the queryset is re-evaluated ? |
It depends on the paginator, but, for LimitOffsetPagination it's rest_framework/pagination.py:307 (first one is line 303->53). For CursorPagination, this isn't an issue, since it doesn't do the count. For PageNumberPagination, this is done by DjangoPaginator (first one is 59->78). While Django behaves the same, that's a separate issue and I will probably put in a ticket there as well. My main concern is whether this is a behaviour that seems sensible (it does to me). |
I've actually went and tested that, and it's not true. Django has an extra bit which caps the upper limit to the count and in qs.query.set_limits, if low and high are equal, it returns an empty QS, without going to the database. So, I guess that answers my question whether this is intended behaviour or not, I'll make a PR tonight when I get home to unify the behaviour. |
DRF 3.4.7 is the same version run by edx/credentials. Release notes are at http://www.django-rest-framework.org/topics/release-notes/#34x-series. Highlights include: support for Django 1.10 (encode/django-rest-framework#4158 - sigh), support for schema generation (encode/django-rest-framework#4179 - required for newer versions of django-rest-swagger), and a change that prevents paginated views from re-running queries when count queries return 0 (encode/django-rest-framework#4201 - this explains the expected query count changes made in tests). LEARNER-1590
DRF 3.4.7 is the same version run by edx/credentials. Release notes are at http://www.django-rest-framework.org/topics/release-notes/#34x-series. Highlights include: - [Support for Django 1.10](encode/django-rest-framework#4158) - sigh - [Support for schema generation](encode/django-rest-framework#4179) - required for newer versions of django-rest-swagger - A [change](encode/django-rest-framework#4201) that prevents paginated views from re-running queries when count queries return 0 - this explains the expected query count changes made in tests LEARNER-1590
DRF 3.4.7 is the same version run by edx/credentials. Release notes are at http://www.django-rest-framework.org/topics/release-notes/#34x-series. Highlights include: 1. [Support for Django 1.10](encode/django-rest-framework#4158) - sigh 2. [Support for schema generation](encode/django-rest-framework#4179) - required for newer versions of django-rest-swagger 3. A change that [prevents paginated views from re-running queries](encode/django-rest-framework#4201) when count queries return 0 - this explains the expected query count changes made in tests LEARNER-1590
DRF 3.4.7 is the same version run by edx/credentials. Release notes are at http://www.django-rest-framework.org/topics/release-notes/#34x-series. Highlights include: 1. [Support for Django 1.10](encode/django-rest-framework#4158) - sigh 2. [Support for schema generation](encode/django-rest-framework#4179) - required for newer versions of django-rest-swagger 3. A change that [prevents paginated views from re-running queries](encode/django-rest-framework#4201) when count queries return 0 - this explains the expected query count changes made in tests LEARNER-1590
Checklist
master
branch of Django REST framework.Steps to reproduce
Expected behavior
Actual behavior
This isn't a problem in the case I described, but in some cases the query can get quite complex and slow. Even if the view isn't wrapped in a transaction and it is possible to get rows on the second run, the results will be inconsistent, but the maybe expensive query is re-run.
The text was updated successfully, but these errors were encountered: