use ignore_conflicts when inserting references

don't pass ignore_conflicts if backend is mssql

check for feature not DB engine
pull/11046/head
chris48s 2023-10-10 12:55:27 +01:00 zatwierdzone przez jacobtoppm
rodzic 912e2b6ea7
commit 4219488a3c
3 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -55,6 +55,7 @@ Changelog
* Fix: Prevent crash on snippet inspect view when displaying a null foreign key to an image (Sage Abdullah)
* Fix: Ensure that pages in moderation show as "Live + In Moderation" in the page explorer rather than "Live + Draft" (Sage Abdullah)
* Fix: Prevent error when updating reference index for objects with a lazy ParentalKey-related object (Chris Shaw)
* Fix: Ignore conflicts when inserting reference index entries to prevent race conditions causing uniqueness errors (Chris Shaw)
* Docs: Document `WAGTAILADMIN_BASE_URL` on "Integrating Wagtail into a Django project" page (Shreshth Srivastava)
* Docs: Replace incorrect screenshot for authors listing on tutorial (Shreshth Srivastava)
* Docs: Add documentation for building non-model-based choosers using the _queryish_ library (Matt Westcott)

Wyświetl plik

@ -71,6 +71,7 @@ depth: 1
* Prevent crash on snippet inspect view when displaying a null foreign key to an image (Sage Abdullah)
* Ensure that pages in moderation show as "Live + In Moderation" in the page explorer rather than "Live + Draft" (Sage Abdullah)
* Prevent error when updating reference index for objects with a lazy ParentalKey-related object (Chris Shaw)
* Ignore conflicts when inserting reference index entries to prevent race conditions causing uniqueness errors (Chris Shaw)
### Documentation

Wyświetl plik

@ -2,7 +2,7 @@ import uuid
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRel
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db import connection, models
from django.utils.functional import cached_property
from django.utils.text import capfirst
from django.utils.translation import gettext_lazy as _
@ -456,6 +456,11 @@ class ReferenceIndex(models.Model):
# Construct the set of reference records that have been found on the object but are not
# already present in the database
new_references = references - set(existing_references.keys())
bulk_create_kwargs = {}
if connection.features.supports_ignore_conflicts:
bulk_create_kwargs["ignore_conflicts"] = True
# Create database records for those reference records
cls.objects.bulk_create(
[
@ -470,7 +475,8 @@ class ReferenceIndex(models.Model):
content_path_hash=cls._get_content_path_hash(content_path),
)
for to_content_type_id, to_object_id, model_path, content_path in new_references
]
],
**bulk_create_kwargs,
)
# Delete removed references