Skip to content

Commit

Permalink
fixes #19263
Browse files Browse the repository at this point in the history
  • Loading branch information
biern committed Feb 23, 2013
1 parent 7ec2a21 commit 2b76f19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions django/db/models/sql/where.py
Expand Up @@ -204,6 +204,10 @@ def make_atom(self, child, qn, connection):
raise EmptyResultSet raise EmptyResultSet
if extra: if extra:
return ('%s IN %s' % (field_sql, extra), params) return ('%s IN %s' % (field_sql, extra), params)
if not params:
# Empty params would generate invalid sql in subquery
raise EmptyResultSet

max_in_list_size = connection.ops.max_in_list_size() max_in_list_size = connection.ops.max_in_list_size()
if max_in_list_size and len(params) > max_in_list_size: if max_in_list_size and len(params) > max_in_list_size:
# Break up the params list into an OR of manageable chunks. # Break up the params list into an OR of manageable chunks.
Expand Down
15 changes: 15 additions & 0 deletions tests/regressiontests/queries/tests.py
Expand Up @@ -2021,6 +2021,9 @@ def setUp(self):
Article.objects.create(name='three', created=datetime.datetime.now()) Article.objects.create(name='three', created=datetime.datetime.now())
Article.objects.create(name='four', 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): def test_tickets_7698_10202(self):
# People like to slice with '0' as the high-water mark. # People like to slice with '0' as the high-water mark.
self.assertQuerysetEqual(Article.objects.all()[0:0], []) self.assertQuerysetEqual(Article.objects.all()[0:0], [])
Expand All @@ -2036,6 +2039,18 @@ def test_empty_resultset_sql(self):
# ticket #12192 # ticket #12192
self.assertNumQueries(0, lambda: list(Number.objects.all()[1:1])) self.assertNumQueries(0, lambda: list(Number.objects.all()[1:1]))


def test_empty_sliced_subquery(self):
# ticket #19263 - testing subqueries
self.assertEqual(
Eaten.objects.filter(food__in=Food.objects.all()[0:0]).count(),
0)

def test_empty_sliced_subquery_exclude(self):
# ticket #19263 - testing subqueries
self.assertEqual(
Eaten.objects.exclude(food__in=Food.objects.all()[0:0]).count(),
1)



class EscapingTests(TestCase): class EscapingTests(TestCase):
def test_ticket_7302(self): def test_ticket_7302(self):
Expand Down

0 comments on commit 2b76f19

Please sign in to comment.