batch_size param overrides compatible batch size calculation. This looks
like a bug as bulk_update properly picks the minimum of two:
https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L504
I suggest using similar batch_size = min(batch_size, max_batch_size) if
batch_size else max_batch_size
logic in bulk_create as well. I am happy to open a PR for it.
--
Ticket URL: <https://code.djangoproject.com/ticket/30827>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> At this line:
> https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L1197
>
> batch_size param overrides compatible batch size calculation. This looks
> like a bug as bulk_update properly picks the minimum of two:
> https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L504
>
> I suggest using similar batch_size = min(batch_size, max_batch_size) if
> batch_size else max_batch_size
> logic in bulk_create as well. I am happy to open a PR for it.
New description:
batch_size param overrides compatible batch size calculation. This looks
like a bug as bulk_update properly picks the minimum of two:
https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L504
I suggest using similar
{{{
batch_size = min(batch_size, max_batch_size) if batch_size else
max_batch_size
}}}
logic in bulk_create as well. I am happy to open a PR for it.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:1>
* cc: Georgi Yanchev (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:2>
* has_patch: 0 => 1
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted
Comment:
I guess testing it will be harder than the fix!
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:3>
* component: Uncategorized => Database layer (models, ORM)
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:4>
* Attachment "ticket30827RegressionTests.diff" added.
Adding regression tests
* needs_tests: 1 => 0
Comment:
Hi!
I added a couple of tests to the patch. Since this is the first time I'm
contributing to django, I'd love to hear any feedback or advice.\\
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:5>
Comment (by felixxm):
Chetan Khanna, thanks, I added your test to the patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:6>
* owner: nobody => Ahmet Kucuk
* status: new => assigned
* version: 2.2 => master
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"09578f6dfb757c55f107e30a85434cedeb47465a" 09578f6]:
{{{
#!CommitTicketReference repository=""
revision="09578f6dfb757c55f107e30a85434cedeb47465a"
Fixed #30827 -- Made batch_size arg of QuerySet.bulk_create() respect
DatabaseOperations.bulk_batch_size().
Thanks Chetan Khanna for tests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:8>
Comment (by Chetan Khanna):
Glad :)
--
Ticket URL: <https://code.djangoproject.com/ticket/30827#comment:9>