Fix: prevent orphaned versions from bulk delete (#14030)

This commit is contained in:
shamoon
2026-09-09 08:48:59 -07:00
committed by GitHub
parent 43a8d7d412
commit 8d1bc5dd24
6 changed files with 97 additions and 6 deletions
+10 -2
View File
@@ -1,4 +1,5 @@
import datetime
import uuid
from pathlib import Path
from typing import Final
@@ -514,13 +515,20 @@ class Document(SoftDeleteModel, ModelWithOwner): # type: ignore[django-manager-
def delete(
self,
*args,
transaction_id=None,
**kwargs,
):
# If deleting a root document, move all its versions to trash as well.
# Versions must share the root's transaction ID so they are restored
# together by django-softdelete.
if transaction_id is None:
transaction_id = uuid.uuid4()
if self.root_document_id is None:
Document.objects.filter(root_document=self).delete()
Document.objects.filter(root_document=self).delete(
transaction_id=transaction_id,
)
return super().delete(
*args,
transaction_id=transaction_id,
**kwargs,
)