Re: [Django] #36502: bulk_create on Postgres doesn't use the unnest strategy when foreign keys are involved since 5.2.1 (was: bulk INSERT is not using UNNEST when a field is a FK on PostgreSQL)

3 views
Skip to first unread message

Django

unread,
Jul 9, 2025, 12:25:17 PM7/9/25
to django-...@googlegroups.com
#36502: bulk_create on Postgres doesn't use the unnest strategy when foreign keys
are involved since 5.2.1
-------------------------------------+-------------------------------------
Reporter: canardoFR | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres | Triage Stage: Accepted
bulk_create unnest foreignkey |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* cc: Simon Charette (added)
* has_patch: 1 => 0
* keywords: => postgres bulk_create unnest foreignkey
* needs_better_patch: 1 => 0
* owner: (none) => Simon Charette
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
* status: new => assigned
* summary: bulk INSERT is not using UNNEST when a field is a FK on
PostgreSQL =>
bulk_create on Postgres doesn't use the unnest strategy when foreign
keys are involved since 5.2.1
* type: Uncategorized => Bug

Comment:

From looking at your attached monkey patching solution you seem to want to
make sure the optimization introduced in Django 5.2 on Postgres to make
use of `UNNEST` (see #35936) is enabled when foreign keys are involved
which appears to have been inadvertently disabled by
764af7a3d6c0b543dcf659a2c327f214da768fe4 (see #36289).

Going to move a release blocker since this a regression in 5.2.1.
--
Ticket URL: <https://code.djangoproject.com/ticket/36502#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages