Model creation in autocommit mode.

65 views
Skip to first unread message

Florian Apolloner

unread,
Sep 26, 2018, 2:56:34 PM9/26/18
to Django developers (Contributions to Django itself)
Hi there,

a fun issue came up on IRC today: Even when in autocommit mode, Django starts a transaction when doing Model.objects.create (https://github.com/django/django/blob/fb2964a4106b1282c4179b6fbbd0374f5be1ccac/django/db/models/base.py#L752). This makes some sense when there are parents to be saved also, but imo results in a rather high database roundtrip number for the simple case where there is a single model without inheritance. Does anyone know why we do this?

I've created a really simple patch https://github.com/django/django/pull/10448 which already (mostly) passes the testsuite.

Cheers,
Florian

Tim Graham

unread,
Sep 26, 2018, 3:54:05 PM9/26/18
to Django developers (Contributions to Django itself)

Florian Apolloner

unread,
Sep 26, 2018, 4:10:27 PM9/26/18
to Django developers (Contributions to Django itself)
Jupp, that ticket at least shows that I am not the first one to stumble onto this :) Baring no objections I will at least try to fix it for the "easy" cases; seems like an easy win.
Reply all
Reply to author
Forward
0 new messages