1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #33799, Refs #31685 -- Added parameters for updating conflicts to QuerySeta.abulk_create().

This commit is contained in:
DhruvaPatil98
2022-06-23 12:32:41 +05:30
committed by Mariusz Felisiak
parent e6f36ea0a9
commit c627226d05
2 changed files with 29 additions and 2 deletions

View File

@@ -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: