Skip to content

Paginators always repeat the query even if the count is 0 #4201

Closed
@gcbirzan

Description

@gcbirzan

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.) - This can be done with a third party library, but I feel that it's a sensible improvement.
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.) - I haven't, since I'm not sure this is considered a bug/desired feature.

Steps to reproduce

  • Add a paginated view for an empty model (Only applies to LimitOffsetPagination)
  • Make a GET request.

Expected behavior

  • If the count query returns 0, the actual query shouldn't be re-run

Actual behavior

  • The query is re-run.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions