From d3cf24e9b415b41f570c9f426b2cd113b5fdb4de Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Tue, 3 Jun 2025 21:53:10 -0400 Subject: Refs #36430, #36416, #34378 -- Simplified batch size calculation in QuerySet.in_bulk(). --- django/db/models/query.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'django') diff --git a/django/db/models/query.py b/django/db/models/query.py index 9f245b02ca..7ae9f53bfd 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1187,10 +1187,8 @@ class QuerySet(AltersData): if not id_list: return {} filter_key = "{}__in".format(field_name) - 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) + batch_size = connections[self.db].ops.bulk_batch_size([opts.pk], 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): -- cgit v1.3