summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMatthias Erll <matthias@precisdigital.com>2014-05-17 14:59:57 +0200
committerTim Graham <timograham@gmail.com>2017-05-31 19:34:56 -0400
commiteee34ef64c026e3274c6d1b4fa2baffbc956b954 (patch)
tree1ed5087f7396fafc49560e8106cf23c6d1afd99c /docs
parent84fb50df670c8126983c9f0fd4a5c30dbe57b684 (diff)
Fixed #22550 -- Prohibited QuerySet.last()/reverse() after slicing.
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/2.0.txt12
-rw-r--r--docs/topics/db/queries.txt3
2 files changed, 15 insertions, 0 deletions
diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt
index 39df2d891d..044123485d 100644
--- a/docs/releases/2.0.txt
+++ b/docs/releases/2.0.txt
@@ -314,6 +314,18 @@ If you wish to keep this restriction in the admin when editing users, set
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)
+``QuerySet.reverse()`` and ``last()`` are prohibited after slicing
+------------------------------------------------------------------
+
+Calling ``QuerySet.reverse()`` or ``last()`` on a sliced queryset leads to
+unexpected results due to the slice being applied after reordering. This is
+now prohibited, e.g.::
+
+ >>> Model.objects.all()[:2].reverse()
+ Traceback (most recent call last):
+ ...
+ TypeError: Cannot reverse a query once a slice has been taken.
+
Miscellaneous
-------------
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
index b95173773b..b6263a9f42 100644
--- a/docs/topics/db/queries.txt
+++ b/docs/topics/db/queries.txt
@@ -361,6 +361,9 @@ every *second* object of the first 10::
>>> Entry.objects.all()[:10:2]
+Further filtering or ordering of a sliced queryset is prohibited due to the
+ambiguous nature of how that might work.
+
To retrieve a *single* object rather than a list
(e.g. ``SELECT foo FROM bar LIMIT 1``), use a simple index instead of a
slice. For example, this returns the first ``Entry`` in the database, after