Re-add ability to customize paginator class · Issue #3684 · encode/django-rest-framework (original) (raw)

As part of the 3.1 release DRF lost the ability to override the paginator class and replaced it with a custom implementation that uses Django's default paginator in the critical paginate_queryset method. This change severely limits the architectural separation of data pagination from view level pagination behavior.

E.g. code that happens when the pagination page queryset is evaluated now needs to be handled in an overridden Pagination.paginate_queryset method. Since the instantiation of the paginator is in the middle of the default PageNumberPagination.paginate_queryset method working around this deprecation results in effectively completely rewriting it and making it a future tech debt concern. The alternative to run queryset evaluation time code in paginate_queryset and then call the parent paginate_queryset is equally not satisfactory as at that point the page object hasn't been created yet which contains vital information that is not available on the pagination instance. Fetching that data after the fact would again require evaluation the queryset, again not wanted.

As such the removal of the ability to override the paginator class is a step backwards that leads to brittle workarounds (monkeypatches) and removed the ability to hook into a key moment of pagination. Please advise what I can do to improve this.