Fixed #22550 -- Raise error on QuerySet reverse after slicing. #2677

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@@ -836,6 +836,8 @@ def reverse(self):
"""
Reverses the ordering of the QuerySet.
"""
+ assert self.query.can_filter(), \

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham Jun 13, 2014

Member

I see we use assert elsewhere, but I would prefer to raise an exception as asserts are ignored when running with python -O.

@timgraham

timgraham Jun 13, 2014

Member

I see we use assert elsewhere, but I would prefer to raise an exception as asserts are ignored when running with python -O.

@@ -361,6 +361,10 @@ every *second* object of the first 10::
>>> Entry.objects.all()[:10:2]
+Filtering and ordering operations are not possible after slicing, as they would
+lead to inconsistent results across different database backends. For pagination
+purposes, filters and sorting should be applied before slicing.

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham Jun 13, 2014

Member

comma after filters

@timgraham

timgraham Jun 13, 2014

Member

comma after filters

@@ -675,3 +675,24 @@ class Student(models.Model):
class Classroom(models.Model):
school = models.ForeignKey(School)
students = models.ManyToManyField(Student, related_name='classroom')
+
+
+@python_2_unicode_compatible

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham Jun 13, 2014

Member

If it's possible to reuse existing models, that's ideal as adding additional models increases the time needed to run the tests.

@timgraham

timgraham Jun 13, 2014

Member

If it's possible to reuse existing models, that's ideal as adding additional models increases the time needed to run the tests.

- Company, Employment, CustomPk, CustomPkTag, Classroom, School, Student)
+ Company, Employment, CustomPk, CustomPkTag, Classroom, School, Student,
+ ModelWithoutOrdering, ModelWithOrdering)
+

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham Jun 13, 2014

Member

remove extra newline (please check code with flake8)

@timgraham

timgraham Jun 13, 2014

Member

remove extra newline (please check code with flake8)

@timgraham

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham Jun 13, 2014

Member

I guess this may also need a mention in the 1.8 release notes as a backwards incompatible change.

Member

timgraham commented Jun 13, 2014

I guess this may also need a mention in the 1.8 release notes as a backwards incompatible change.

@timgraham

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham Oct 30, 2014

Member

Closing due to lack of follow-up. Please send a new PR if someone can update this one. Thanks!

Member

timgraham commented Oct 30, 2014

Closing due to lack of follow-up. Please send a new PR if someone can update this one. Thanks!

@timgraham timgraham closed this Oct 30, 2014

michael-k added a commit to michael-k/django that referenced this pull request Feb 14, 2017

michael-k added a commit to michael-k/django that referenced this pull request Feb 14, 2017

michael-k added a commit to michael-k/django that referenced this pull request Feb 14, 2017

michael-k added a commit to michael-k/django that referenced this pull request Feb 14, 2017

michael-k added a commit to michael-k/django that referenced this pull request Feb 14, 2017

michael-k added a commit to michael-k/django that referenced this pull request Feb 14, 2017

michael-k added a commit to michael-k/django that referenced this pull request Feb 14, 2017

michael-k added a commit to michael-k/django that referenced this pull request Feb 24, 2017

michael-k added a commit to michael-k/django that referenced this pull request Feb 24, 2017

michael-k added a commit to michael-k/django that referenced this pull request Mar 6, 2017

michael-k added a commit to michael-k/django that referenced this pull request May 25, 2017

michael-k added a commit to michael-k/django that referenced this pull request May 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment