Index: django/db/models/sql/where.py =================================================================== --- django/db/models/sql/where.py (revision 13680) +++ django/db/models/sql/where.py (working copy) @@ -178,7 +178,32 @@ raise EmptyResultSet if extra: return ('%s IN %s' % (field_sql, extra), params) - return ('%s IN (%s)' % (field_sql, ', '.join(['%s'] * len(params))), + #break up in clauses over 1000 itens. This is to specifially support an Oracle limit of 1000 items in an in clause + MAX_IN_PARAMS = 1000 + if len(params) > MAX_IN_PARAMS: + in_clause_elements = [] #used to concatinate elements later + is_first = True #avoid putting ' OR ' in front of first in clause group + cur_min = 0 #starting point of current parameter elements + in_clause_elements.append('(') + while cur_min <= len(params): + if not is_first: + in_clause_elements.append(' OR ') + else: + is_first = False + num_params = 0 + if cur_min + MAX_IN_PARAMS > len(params): + #we are at the end so only use the remaining parameters + num_params = len(params) - cur_min + else: + #use full 1000 paramaters + num_params = MAX_IN_PARAMS + in_clause_elements.append('(%s IN (%s))' % (field_sql, ', '.join(['%s'] * num_params))) + cur_min += MAX_IN_PARAMS + + in_clause_elements.append(')') + return ''.join(in_clause_elements), params + else: + return ('%s IN (%s)' % (field_sql, ', '.join(['%s'] * len(params))), params) elif lookup_type in ('range', 'year'): return ('%s BETWEEN %%s and %%s' % field_sql, params) Index: tests/modeltests/where/__init__.py =================================================================== Index: tests/modeltests/where/models.py =================================================================== --- tests/modeltests/where/models.py (revision 0) +++ tests/modeltests/where/models.py (revision 0) @@ -0,0 +1,4 @@ +from django.db import models + +class A(models.Model): + x = models.IntegerField() Index: tests/modeltests/where/tests.py =================================================================== --- tests/modeltests/where/tests.py (revision 0) +++ tests/modeltests/where/tests.py (revision 0) @@ -0,0 +1,20 @@ +from django.test import TestCase + +from models import A + +class WhereTest(TestCase): + ''' + Unfortunately this test does not work because SQLite3 has a predefined limit of 1000 parameters in a query. + SQLite3 does expose a setting to increase this but it is only exposed in the C or Python APSW libraries. + http://www.sqlite.org/capi3ref.html#SQLITE_LIMIT_ATTACHED + ''' + + def testSimple(self): + xs = [] + #create 1001 A types + for i in range(1001): + A.objects.create(x=i) + xs.append(i) + + queried = A.objects.filter(x__in=xs) + self.assertEquals(len(queried), 1001)