﻿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
34225	bulk_create() raises IntegrityError when another constraint exists on set of fields.	Victor J. Fuente	nobody	"bulk_create on 4.1 perform a bulk_update when a unique constraint fails.

But on this example, when the constraint fails, an integrity Error occur and no update is in place 


{{{

class Test(models.Model):

    field1 = models.IntegerField(null=True, blank=True)
    field2 = models.IntegerField(null=True, blank=True)
    count = models.IntegerField(null=True, blank=True)

    class Meta:

        db_table = ""test""

        constraints = [
            models.UniqueConstraint(
                models.functions.Coalesce(""field1"", 0),
                models.functions.Coalesce(""field2"", 0),
                name=""test_coal_unique"",
            ),
            models.UniqueConstraint(
                ""field1"",
                ""field2"",
                name=""test_unique"",
            ),
        ]


t1 = Test(field1=1,field2=None,count=1)
t2 = Test(field1=1,field2=None,count=2)

Test.objects.bulk_create([t1, t2], ignore_conflicts=False, update_conflicts=True, unique_fields=['field1','field2'], update_fields = ['count'])

}}}

{{{
django.db.utils.IntegrityError: duplicate key value violates unique constraint ""test_coal_unique""
DETAIL:  Key (COALESCE(field1, 0), COALESCE(field2, 0))=(1, 0) already exists.
}}}"	Bug	closed	Database layer (models, ORM)	4.1	Normal	invalid	#bulk_create		Unreviewed	0	0	0	0	0	0
