#36430: bulk_batch_size() special-cases single field on SQLite according to
outdated limit
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
SQLITE_MAX_COMPOUND_SELECT, | Unreviewed
bulk_create |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Old description:
New description:
trouble selecting 501 objects). (You can also adjust
`test_max_batch_size()` to provide a s
Comment (by Jacob Walls):
Here's a rough test after all to demo, just adjust `test_max_batch_size`
like this:
{{{#!diff
diff --git a/tests/bulk_create/tests.py b/tests/bulk_create/tests.py
index d590a292de..fd30ca48f7 100644
--- a/tests/bulk_create/tests.py
+++ b/tests/bulk_create/tests.py
@@ -296,7 +296,7 @@ class BulkCreateTests(TestCase):
@skipUnlessDBFeature("has_bulk_insert")
def test_max_batch_size(self):
objs = [Country(name=f"Country {i}") for i in range(1000)]
- fields = ["name", "iso_two_letter", "description"]
+ fields = ["pk"]
max_batch_size = connection.ops.bulk_batch_size(fields, objs)
with self.assertNumQueries(ceil(len(objs) / max_batch_size)):
Country.objects.bulk_create(objs)
}}}
----
The test fails as it was *more* efficient than expected:
{{{#!py
======================================================================
FAIL: test_max_batch_size
(bulk_create.tests.BulkCreateTests.test_max_batch_size)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/.../django/tests/bulk_create/tests.py", line 301, in
test_max_batch_size
with self.assertNumQueries(ceil(len(objs) / max_batch_size)):
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 1 != 2 : 1 queries executed, 2 expected
Captured queries were:
1. INSERT INTO "bulk_create_country" ("name", "iso_two_letter",
"description") VALUES ('Country 0', '', ''), ('Country 1', '', ''),
('Country 2', '', ''), ('Country 3', '', ...
----------------------------------------------------------------------
Ran 2 tests in 0.025s
FAILED (failures=1)
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/36430#comment:1>