mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Strip annotations from queryset when retrieving object count for API pagination
This commit is contained in:
parent
2b1516ea79
commit
240d22696f
@ -81,10 +81,17 @@ class OptionalLimitOffsetPagination(LimitOffsetPagination):
|
||||
|
||||
def paginate_queryset(self, queryset, request, view=None):
|
||||
|
||||
try:
|
||||
self.count = queryset.count()
|
||||
except (AttributeError, TypeError):
|
||||
if hasattr(queryset, 'all'):
|
||||
# TODO: This breaks filtering by annotated values
|
||||
# Make a clone of the queryset with any annotations stripped (performance hack)
|
||||
qs = queryset.all()
|
||||
qs.query.annotations.clear()
|
||||
self.count = qs.count()
|
||||
|
||||
else:
|
||||
# We're dealing with an iterable, not a QuerySet
|
||||
self.count = len(queryset)
|
||||
|
||||
self.limit = self.get_limit(request)
|
||||
self.offset = self.get_offset(request)
|
||||
self.request = request
|
||||
|
Loading…
Reference in New Issue
Block a user