[Django] #28917: Paginator shows ordering warning on an empty .none() queryset

8 views
Skip to first unread message

Django

unread,
Dec 12, 2017, 11:32:54 AM12/12/17
to django-...@googlegroups.com
#28917: Paginator shows ordering warning on an empty .none() queryset
-----------------------------------------+------------------------
Reporter: Jeremy Lainé | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Paginator (sanely!) does a check to verify that the queryset it is passed
is ordered, and if it isn't, shows a warning.

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28917>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 18, 2017, 7:51:42 PM12/18/17
to django-...@googlegroups.com
#28917: Paginator shows ordering warning on an empty .none() queryset
-------------------------------+--------------------------------------
Reporter: Jeremy Lainé | Owner: Junji Wei
Type: Bug | Status: assigned

Component: Generic views | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Junji Wei):

* status: new => assigned
* owner: nobody => Junji Wei


--
Ticket URL: <https://code.djangoproject.com/ticket/28917#comment:1>

Django

unread,
Dec 18, 2017, 10:04:55 PM12/18/17
to django-...@googlegroups.com
#28917: Remove paginator's unordered queryset warning for a .none() queryset
-------------------------------------+-------------------------------------

Reporter: Jeremy Lainé | Owner: Junji Wei
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Bug => Cleanup/optimization
* component: Generic views => Core (Other)
* stage: Unreviewed => Accepted


Old description:

> Paginator (sanely!) does a check to verify that the queryset it is passed
> is ordered, and if it isn't, shows a warning.
>
> 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.

New description:

`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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28917#comment:2>

Django

unread,
Dec 20, 2017, 7:37:30 PM12/20/17
to django-...@googlegroups.com
#28917: Remove paginator's unordered queryset warning for a .none() queryset
-------------------------------------+-------------------------------------
Reporter: Jeremy Lainé | Owner: Junji Wei
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Junji Wei):

PR https://github.com/django/django/pull/9479

--
Ticket URL: <https://code.djangoproject.com/ticket/28917#comment:3>

Django

unread,
Dec 20, 2017, 11:51:27 PM12/20/17
to django-...@googlegroups.com
#28917: Remove paginator's unordered queryset warning for a .none() queryset
-------------------------------------+-------------------------------------
Reporter: Jeremy Lainé | Owner: Junji Wei
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sergey Fedoseev):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/28917#comment:4>

Django

unread,
Feb 9, 2018, 9:08:51 AM2/9/18
to django-...@googlegroups.com
#28917: Remove paginator's unordered queryset warning for a .none() queryset
-------------------------------------+-------------------------------------
Reporter: Jeremy Lainé | Owner: Junji Wei
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 0 => 1


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28917#comment:5>

Django

unread,
Jul 16, 2018, 4:15:56 AM7/16/18
to django-...@googlegroups.com
#28917: Remove paginator's unordered queryset warning for a .none() queryset
-------------------------------------+-------------------------------------
Reporter: Jeremy Lainé | Owner: (none)
Type: | Status: new

Cleanup/optimization |
Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* owner: Junji Wei => (none)
* needs_better_patch: 1 => 0
* status: assigned => new
* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/10184 New PR] from Josh Schneier.

Minor change to docstring suggested but otherwise, looks good.

--
Ticket URL: <https://code.djangoproject.com/ticket/28917#comment:6>

Django

unread,
Jul 16, 2018, 2:49:43 PM7/16/18
to django-...@googlegroups.com
#28917: Remove paginator's unordered queryset warning for a .none() queryset
-------------------------------------+-------------------------------------
Reporter: Jeremy Lainé | Owner: Tim
Type: | Graham <timograham@…>
Cleanup/optimization | Status: closed

Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* owner: (none) => Tim Graham <timograham@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"4d48ddd8f93800a80330ec1dee7b7d4afe6ea95a" 4d48ddd]:
{{{
#!CommitTicketReference repository=""
revision="4d48ddd8f93800a80330ec1dee7b7d4afe6ea95a"
Fixed #28917 -- Prevented Paginator's unordered warning on EmptyQuerySet.

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28917#comment:7>

Reply all
Reply to author
Forward
0 new messages