def bulk_create(
self,
objs: Iterable[models.Model],
*,
batch_size: int | None = None,
ignore_conflicts: bool = False,
update_conflicts: bool = False,
update_fields: Iterable[str] | None = None,
unique_fields: Iterable[str] | None = None,
) -> list[models.Model]:
if not self._activity_enabled():
return super().bulk_create(
objs,
batch_size=batch_size,
ignore_conflicts=ignore_conflicts,
update_conflicts=update_conflicts,
update_fields=update_fields,
unique_fields=unique_fields,
)
with transaction.atomic(using=self.db):
created = super().bulk_create(
objs,
batch_size=batch_size,
ignore_conflicts=ignore_conflicts,
update_conflicts=update_conflicts,
update_fields=update_fields,
unique_fields=unique_fields,
)
if update_conflicts:
log.warning(
'bulk_create with update_conflicts cannot distinguish created '
'rows from updated rows; no activity records were created.'
)
else:
self._add_bulk_activity(created, ActivityVerb.CREATED)
return created