Reputation: 686
When using Model.objects.bulk_create()
if an exception occurs during the insertion does it roll back the entire operation or does it continue with the non-conflicting records, and is there any way to know which records were inserted and which threw an error?
Upvotes: 1
Views: 1607
Reputation: 48982
If an exception occurs the entire operation will be rolled back. If you look at the source code you'll see that all database operations are wrapped in transaction.atomic()
.
There's no way of knowing which values caused the conflict. Such information may be available in the database-specific error message, but that's not part of the API.
Note that as of Django 2.2 there will be an ignore_conflicts
parameter that will allow you to explicitly control whether the operation will roll back or whether the conflicts will be ignored.
Upvotes: 3