Loading django/db/models/sql/compiler.py +4 −1 Original line number Diff line number Diff line Loading @@ -484,7 +484,10 @@ class SQLCompiler(object): if obj.low_mark == 0 and obj.high_mark is None and not self.query.distinct_fields: # If there is no slicing in use, then we can safely drop all ordering obj.clear_ordering(True) return obj.get_compiler(connection=self.connection).as_sql(subquery=True) nested_sql = obj.get_compiler(connection=self.connection).as_sql(subquery=True) if nested_sql == ('', ()): raise EmptyResultSet return nested_sql def get_default_columns(self, start_alias=None, opts=None, from_parent=None): """ Loading tests/queries/tests.py +9 −0 Original line number Diff line number Diff line Loading @@ -2362,6 +2362,9 @@ class WeirdQuerysetSlicingTests(BaseQuerysetTest): Article.objects.create(name='three', created=datetime.datetime.now()) Article.objects.create(name='four', created=datetime.datetime.now()) food = Food.objects.create(name='spam') Eaten.objects.create(meal='spam with eggs', food=food) def test_tickets_7698_10202(self): # People like to slice with '0' as the high-water mark. self.assertQuerysetEqual(Article.objects.all()[0:0], []) Loading @@ -2377,6 +2380,12 @@ class WeirdQuerysetSlicingTests(BaseQuerysetTest): # ticket #12192 self.assertNumQueries(0, lambda: list(Number.objects.all()[1:1])) def test_empty_sliced_subquery(self): self.assertEqual(Eaten.objects.filter(food__in=Food.objects.all()[0:0]).count(), 0) def test_empty_sliced_subquery_exclude(self): self.assertEqual(Eaten.objects.exclude(food__in=Food.objects.all()[0:0]).count(), 1) class EscapingTests(TestCase): def test_ticket_7302(self): Loading Loading
django/db/models/sql/compiler.py +4 −1 Original line number Diff line number Diff line Loading @@ -484,7 +484,10 @@ class SQLCompiler(object): if obj.low_mark == 0 and obj.high_mark is None and not self.query.distinct_fields: # If there is no slicing in use, then we can safely drop all ordering obj.clear_ordering(True) return obj.get_compiler(connection=self.connection).as_sql(subquery=True) nested_sql = obj.get_compiler(connection=self.connection).as_sql(subquery=True) if nested_sql == ('', ()): raise EmptyResultSet return nested_sql def get_default_columns(self, start_alias=None, opts=None, from_parent=None): """ Loading
tests/queries/tests.py +9 −0 Original line number Diff line number Diff line Loading @@ -2362,6 +2362,9 @@ class WeirdQuerysetSlicingTests(BaseQuerysetTest): Article.objects.create(name='three', created=datetime.datetime.now()) Article.objects.create(name='four', created=datetime.datetime.now()) food = Food.objects.create(name='spam') Eaten.objects.create(meal='spam with eggs', food=food) def test_tickets_7698_10202(self): # People like to slice with '0' as the high-water mark. self.assertQuerysetEqual(Article.objects.all()[0:0], []) Loading @@ -2377,6 +2380,12 @@ class WeirdQuerysetSlicingTests(BaseQuerysetTest): # ticket #12192 self.assertNumQueries(0, lambda: list(Number.objects.all()[1:1])) def test_empty_sliced_subquery(self): self.assertEqual(Eaten.objects.filter(food__in=Food.objects.all()[0:0]).count(), 0) def test_empty_sliced_subquery_exclude(self): self.assertEqual(Eaten.objects.exclude(food__in=Food.objects.all()[0:0]).count(), 1) class EscapingTests(TestCase): def test_ticket_7302(self): Loading