Opened 7 years ago

Closed 6 years ago

#28917 closed Cleanup/optimization (fixed)

Remove paginator's unordered queryset warning for a .none() queryset

Reported by: Jeremy Lainé Owned by: Tim Graham <timograham@…>
Component: Core (Other) Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

Paginator shows a warning if it receives an unordered queryset.

However, if also emits this warning if passed a queryset which is guaranteed to be empty, for instance Article.objects.none().

Working around this warning involves doing a bizarre Article.objects.none().order_by('id')

I believe there can be legitimate usecases for passing a .none() queryset to a paginator, for instance if a user's permissions are such that we restrict the objects they can view to the empty queryset.

Change History (7)

comment:1 by Junji Wei, 7 years ago

Owner: changed from nobody to Junji Wei
Status: newassigned

comment:2 by Tim Graham, 7 years ago

Component: Generic viewsCore (Other)
Description: modified (diff)
Summary: Paginator shows ordering warning on an empty .none() querysetRemove paginator's unordered queryset warning for a .none() queryset
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

comment:4 by Sergey Fedoseev, 7 years ago

Has patch: set

comment:5 by Carlton Gibson, 7 years ago

Patch needs improvement: set

Discussion on PR led to conclusion that this could be resolved by having QuerySet.ordered return True when the queryset is empty. (Something is ordered if it always returns the same sequence. An empty QuerySet does, i.e. [])

Marking as "Patch needs improvement" pending that change.

comment:6 by Carlton Gibson, 6 years ago

Owner: Junji Wei removed
Patch needs improvement: unset
Status: assignednew
Triage Stage: AcceptedReady for checkin

New PR from Josh Schneier.

Minor change to docstring suggested but otherwise, looks good.

comment:7 by Tim Graham <timograham@…>, 6 years ago

Owner: set to Tim Graham <timograham@…>
Resolution: fixed
Status: newclosed

In 4d48ddd:

Fixed #28917 -- Prevented Paginator's unordered warning on EmptyQuerySet.

Thanks carltongibson for the idea and weijunji for the initial patch.

Note: See TracTickets for help on using tickets.
Back to Top