summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-05-24 14:03:07 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-06-03 17:46:59 +0200
commit2bf4c5b9eaaf0a36cb0fb6c060625a5fb2fcf6c9 (patch)
treea6b0d7b15498790c89ac7ec00c727f2d6ff2917d /django
parent37e5cc6d89b4653f05a1a00af2eb2187c907c935 (diff)
[5.2.x] Fixed #36416 -- Made QuerySet.in_bulk() account for composite pks in id_list.
Backport of 26313bc21932d0d3af278ab387549d63b1f64575 from main.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index bb5462037c..1270141619 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1149,7 +1149,9 @@ class QuerySet(AltersData):
if not id_list:
return {}
filter_key = "{}__in".format(field_name)
- batch_size = connections[self.db].features.max_query_params
+ max_params = connections[self.db].features.max_query_params or 0
+ num_fields = len(opts.pk_fields) if field_name == "pk" else 1
+ batch_size = max_params // num_fields
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.