diff --git a/django/db/models/query.py b/django/db/models/query.py index a169d0c235..be0deb90b0 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -834,11 +834,22 @@ class QuerySet: return objs - async def abulk_create(self, objs, batch_size=None, ignore_conflicts=False): + async def abulk_create( + self, + objs, + batch_size=None, + ignore_conflicts=False, + update_conflicts=False, + update_fields=None, + unique_fields=None, + ): return await sync_to_async(self.bulk_create)( objs=objs, batch_size=batch_size, ignore_conflicts=ignore_conflicts, + update_conflicts=update_conflicts, + update_fields=update_fields, + unique_fields=unique_fields, ) def bulk_update(self, objs, fields, batch_size=None): diff --git a/tests/async_queryset/tests.py b/tests/async_queryset/tests.py index 792797fb9d..1b6dddce1f 100644 --- a/tests/async_queryset/tests.py +++ b/tests/async_queryset/tests.py @@ -6,7 +6,7 @@ from asgiref.sync import async_to_sync, sync_to_async from django.db import NotSupportedError, connection from django.db.models import Sum -from django.test import TestCase, skipUnlessDBFeature +from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from .models import SimpleModel @@ -111,6 +111,22 @@ class AsyncQuerySetTest(TestCase): qs = await SimpleModel.objects.abulk_create(instances) self.assertEqual(len(qs), 10) + @skipUnlessDBFeature("has_bulk_insert", "supports_update_conflicts") + @skipIfDBFeature("supports_update_conflicts_with_target") + @async_to_sync + async def test_update_conflicts_unique_field_unsupported(self): + msg = ( + "This database backend does not support updating conflicts with specifying " + "unique fields that can trigger the upsert." + ) + with self.assertRaisesMessage(NotSupportedError, msg): + await SimpleModel.objects.abulk_create( + [SimpleModel(field=1), SimpleModel(field=2)], + update_conflicts=True, + update_fields=["field"], + unique_fields=["created"], + ) + async def test_abulk_update(self): instances = SimpleModel.objects.all() async for instance in instances: