mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #21160 -- Fixed QuerySet.in_bulk() crash on SQLite when requesting more than 999 ids.
Thanks Andrei Picus and Anssi Kääriäinen for the initial patch and Tim Graham for the review.
This commit is contained in:
parent
899c42cc8e
commit
1b6f05e91f
2 changed files with 22 additions and 1 deletions
|
@ -565,7 +565,17 @@ class QuerySet:
|
|||
if id_list is not None:
|
||||
if not id_list:
|
||||
return {}
|
||||
qs = self.filter(pk__in=id_list).order_by()
|
||||
batch_size = connections[self.db].features.max_query_params
|
||||
id_list = tuple(id_list)
|
||||
# If the database has a limit on the number of query parameters
|
||||
# (e.g. SQLite), retrieve objects in batches if necessary.
|
||||
if batch_size and batch_size < len(id_list):
|
||||
qs = ()
|
||||
for offset in range(0, len(id_list), batch_size):
|
||||
batch = id_list[offset:offset + batch_size]
|
||||
qs += tuple(self.filter(pk__in=batch).order_by())
|
||||
else:
|
||||
qs = self.filter(pk__in=id_list).order_by()
|
||||
else:
|
||||
qs = self._clone()
|
||||
return {obj._get_pk_val(): obj for obj in qs}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue