﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36502	bulk_create on Postgres doesn't use the unnest strategy when foreign keys are involved since 5.2.1	canardoFR	Simon Charette	"Dear Django team,

I'm very fresh & green to Django, but we had to insert millions of lines into a PostgreSQLtable.

We noticed that the ORM was setting up a ""INSERT with UNNEST"" for our bulk_create as long as there was no ForeignKey.

Is related to code here https://github.com/django/django/blob/main/django/db/backends/postgresql/compiler.py, line 42 to 45

I made a quick a dirty test by monkey patching the assemble_as_sql function to created a new list of tested fields ignoring ForeignKey type. I would have done better by testing the ForeignKey type, but as said above, to yound and green on django (some days).

I do not know if code is intentional or if this is a bug, thus the ticket submission.

the patch is attached as a file...

Thanks for reading and cheers,
   Alain R.
"	Bug	closed	Database layer (models, ORM)	5.2	Release blocker	fixed	postgres bulk_create unnest foreignkey	canardoFR Simon Charette	Ready for checkin	1	0	0	0	0	0
