(
self, ignore_conflicts, update_conflicts, update_fields, unique_fields
)
| 738 | return objs_with_pk, objs_without_pk |
| 739 | |
| 740 | def _check_bulk_create_options( |
| 741 | self, ignore_conflicts, update_conflicts, update_fields, unique_fields |
| 742 | ): |
| 743 | if ignore_conflicts and update_conflicts: |
| 744 | raise ValueError( |
| 745 | "ignore_conflicts and update_conflicts are mutually exclusive." |
| 746 | ) |
| 747 | db_features = connections[self.db].features |
| 748 | if ignore_conflicts: |
| 749 | if not db_features.supports_ignore_conflicts: |
| 750 | raise NotSupportedError( |
| 751 | "This database backend does not support ignoring conflicts." |
| 752 | ) |
| 753 | return OnConflict.IGNORE |
| 754 | elif update_conflicts: |
| 755 | if not db_features.supports_update_conflicts: |
| 756 | raise NotSupportedError( |
| 757 | "This database backend does not support updating conflicts." |
| 758 | ) |
| 759 | if not update_fields: |
| 760 | raise ValueError( |
| 761 | "Fields that will be updated when a row insertion fails " |
| 762 | "on conflicts must be provided." |
| 763 | ) |
| 764 | if unique_fields and not db_features.supports_update_conflicts_with_target: |
| 765 | raise NotSupportedError( |
| 766 | "This database backend does not support updating " |
| 767 | "conflicts with specifying unique fields that can trigger " |
| 768 | "the upsert." |
| 769 | ) |
| 770 | if not unique_fields and db_features.supports_update_conflicts_with_target: |
| 771 | raise ValueError( |
| 772 | "Unique fields that can trigger the upsert must be provided." |
| 773 | ) |
| 774 | # Updating primary keys and non-concrete fields is forbidden. |
| 775 | if any(not f.concrete for f in update_fields): |
| 776 | raise ValueError( |
| 777 | "bulk_create() can only be used with concrete fields in " |
| 778 | "update_fields." |
| 779 | ) |
| 780 | if any(f in self.model._meta.pk_fields for f in update_fields): |
| 781 | raise ValueError( |
| 782 | "bulk_create() cannot be used with primary keys in " |
| 783 | "update_fields." |
| 784 | ) |
| 785 | if unique_fields: |
| 786 | if any(not f.concrete for f in unique_fields): |
| 787 | raise ValueError( |
| 788 | "bulk_create() can only be used with concrete fields " |
| 789 | "in unique_fields." |
| 790 | ) |
| 791 | return OnConflict.UPDATE |
| 792 | return None |
| 793 | |
| 794 | def bulk_create( |
| 795 | self, |
no test coverage detected