Skip to content

Commit 46bd922

Browse files
adamchainzjacobtylerwalls
authored andcommitted
Refs #36605 -- Optimized QuerySet.in_bulk() for the empty id_list case.
Now that the setup is a bit more expensive, it makes sense to return earlier for the empty case.
1 parent 1820d35 commit 46bd922

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

django/db/models/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,8 @@ def in_bulk(self, id_list=None, *, field_name="pk"):
11661166
"""
11671167
if self.query.is_sliced:
11681168
raise TypeError("Cannot use 'limit' or 'offset' with in_bulk().")
1169+
if id_list is not None and not id_list:
1170+
return {}
11691171
opts = self.model._meta
11701172
unique_fields = [
11711173
constraint.fields[0]
@@ -1236,8 +1238,6 @@ def get_obj(obj): # noqa: F811
12361238
)
12371239

12381240
if id_list is not None:
1239-
if not id_list:
1240-
return {}
12411241
filter_key = "{}__in".format(field_name)
12421242
id_list = tuple(id_list)
12431243
batch_size = connections[self.db].ops.bulk_batch_size([opts.pk], id_list)

0 commit comments

Comments
 (0)